本文介绍了打开C字符串与NULL字节到一个char数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 GetOpenFileName $ C C>有多个选择的能力。拿起这些文件在LPSTR返回。这里面LPSTR,所选择的文件由空字节分开。我想分裂成LPSTR数组,然后遍历数组。
I am using GetOpenFileName
with multiple select capabilities. The files picked are returned in a LPSTR. Inside this LPSTR, the files selected are separated by NULL bytes. I want to split the LPSTR into an array and then loop over that array.
在PHP,我会做:
$array = explode("\0", $string);
但因为我是新来的C,我不知道我在做什么。
But since I am new to C, I have no idea what I am doing.
推荐答案
您可以通过琴弦做循环:
You could do this to loop through the strings:
char *Buffer; // your null-separated strings
char *Current; // Pointer to the current string
// [...]
for (Current = Buffer; *Current; Current += strlen(Current) + 1)
printf("GetOpenFileName returned: %s\n", Current);
您可以适应这个code创建数组,如果它真的有必要。
You can adapt this code to create arrays if it's really necessary.
这篇关于打开C字符串与NULL字节到一个char数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!