c - 这段代码如何解决?

标签 c input

输入说明:

Your program will be tested on one or more test cases. Each test case is made of a single positive number (0 < n0 < 1, 000, 000).

The last line of the input file has a single zero (which is not part of the test cases.)

我刚刚输入了这样的代码:

int main()
{
    int n0;

    while((scanf("%d", &n0)) != 0)
    {
    ..........
    }

但是为什么输入 0 仍然被处理呢?

最佳答案

while (1) {
  scanf("%d", &n0);
  if (n0==0) break;
  ...
}

关于c - 这段代码如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16615349/

相关文章:

c - K&R 1.6 示例代码显示长整数

java - 控制台输入在不应该等待的时候等待

c++ - 使用for循环从文件C++的中间读取输入

c - 为什么 strcat 会导致崩溃?

javascript - AngularJS - 立即应用指令,格式化货币

javascript - 启用/禁用输入 - knockout

c - C 中的文件输入和数组指针

c++ - 如何从 C++ 程序执行 C# exe

c - 宏中 "do {...} while (0)"和 "{...} ((void)0)"之间的实际区别?

Python-C API : Trouble packing C strings into a tuple