我有一个字符串input
,其中包含由空格分隔的单词。我想使用 sscanf()
来拆分单词,将每个单词存储在 input_word
中并打印出来,但我不确定如何将其放入 while 循环中。
这是我的:
char input[max];
char split_input[max];
/* input gets populated here */
while (sscanf(input," %s", split_input)) {
printf("[%s]\n", split_input);
}
一旦序列中的最后一个单词被拆分,终止循环的条件是什么?
最佳答案
你在那里使用了错误的功能。我可以建议改为使用 strtok()
吗?
在这里阅读 strtok
关于c - C 中 while 循环中的 sscanf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13225394/