我有一个字符串input
,其中包含由空格分隔的单词。我想用sscanf()
拆分单词,将每个单词存储在input_word
中并打印出来,但我不确定如何将它放在while循环中。sscanf()在C中的while循环中
这是我有:
char input[max];
char split_input[max];
/* input gets populated here */
while (sscanf(input," %s", split_input)) {
printf("[%s]\n", split_input);
}
什么会尽快序列中的最后一个字拆终止循环的条件?
见[strtok的()](http://www.cplusplus.com/reference/clibrary/cstring/strtok/) – WhozCraig
@dasblinkenlight时,'scanf'家庭返回'上输入的端EOF'。据我所知,这一直被定义为-1,尽管可能有不同的平台来定义它。 –