将字符串转换为数组。下面是示例:
char myString[] = "This is some text";
printf(myString);
我想要输出为:
["This","is","some","text"]
答案 0 :(得分:0)
正如其他人所提到的,您应该研究使用strtok()
下面是一个简单的示例:
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "This is some text";
char delim[] = " ";
char *ptr = strtok(str, delim);
putchar('[');
while (ptr != NULL)
{
printf("\"%s\"", ptr);
ptr = strtok(NULL, delim);
if(ptr)
{
putchar(',');
}
}
printf("]\n");
return 0;
}