Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如果输入换行符,如何继续扫描?_C - Fatal编程技术网

C 如果输入换行符,如何继续扫描?

C 如果输入换行符,如何继续扫描?,c,C,可能重复: 我希望用户输入几个不同的数字,然后分别测试每个数字 另外,当输入数字0时,我只需要终止程序 这是我的代码的开头: int userInput; printf("please enter some numbers: \n"); while ((scanf("%d", &userInput)) == 1) { ... } 如何在输入0之前一直从用户处获取输入 那个循环不是已经起作用了吗?到底是什么问题?您是否正在寻找类似(!userInput)中断时的if?它工作,但

可能重复:

我希望用户输入几个不同的数字,然后分别测试每个数字

另外,当输入数字
0
时,我只需要终止程序

这是我的代码的开头:

int userInput;
printf("please enter some numbers: \n");
while ((scanf("%d", &userInput)) == 1)
{
    ...
}

如何在输入
0
之前一直从用户处获取输入

那个循环不是已经起作用了吗?到底是什么问题?您是否正在寻找类似(!userInput)中断时的
if?它工作,但如果我输入0,它将继续运行。@carlnorum与:不完全相同,但概念是
scanf()
只告诉您输入的匹配项的数量,0对
int
有效,因此显然您需要另一种类型的检查来确保输入的值不是0谢谢:)@JohnBode
while (scanf("%d", &userInput))
{
    if(userInput == 0)
        break;
    /* do sth */
}
while ((scanf("%d", &userInput) == 1) && (userInput != 0))
{
   ...
}