我想读取多个字段的用户输入,但字段数量未指定。我想读取直到回车符为止的所有单词。我尝试了这段代码,但它不起作用:
char str[256];
while(1)
{
scanf("%s", str);
if(str[strlen(str)] == '\n')
break;
else
printf("Got %s\n", str);
}
用户输入示例:
1. store file1
我需要解析store和file1并跳出循环。
2. store file1 file2
我需要解析store,file1和file2并跳出循环。
想知道如何在回车处跳出循环。
谢谢。
\r\n
分隔的行怎么办? - Jin Kwon