![](/img/trans.png)
[英]How to convert a C string (char array) into a Python string when there are non-ASCII characters in the string?
[英]how to convert an array of characters in c to a string so as to do string operations on it?
假设d [20]数组中有一个字符串。 如何转换为字符串d,以便我可以在诸如strcmp之类的字符串函数中使用它。
它必须为空终止。 那是唯一的要求。 我想你知道该怎么做。
Null终止字符串。 也就是说,将字符串中最后一个字符之后的字符设置为零。
它已经可以使用标准字符串函数进行操作了,因为它是必需的,因此假设它以'\\0'
结尾:它需要知道字符串何时结束。
您可以通过使用memset(string, 0, length)
对其进行设置来准备char[]
的空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.