c - C 中 while 循环中的 sscanf()

标签 c scanf

我有一个字符串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/

相关文章:

python - Python 的 CPU 火焰图

c - 指向字符串数组的指针

c - 退出 scanf 使用较少的参数然后指定

c - fscanf() 格式字符串 "%30[^$]"在 C 中的作用是什么?

c - scanf 和错误的输入使输出变得奇怪

c - 如果语句不识别真实条件?

c - 使用堆栈错误 : incompatible type for argument 1 of 'top' | 反转字符串

c - 矩阵作为 C 中函数的参数

c - 在 C 中为动态数字输入读取字符串时出现问题

c - 带有格式化 float 的 scanf