Why is scanf() causing infinite loop in this code?

后端 未结 16 1461
日久生厌
日久生厌 2020-11-21 06:20

I\'ve a small C-program which just reads numbers from stdin, one at each loop cycle. If the user inputs some NaN, an error should be printed to the console and the input pro

16条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 07:15

    try using this:

    if (scanf("%d", &number) == 0) {
            printf("Err...\n");
            break;
        }
    

    this worked fine for me... try this.. the continue statement is not appropiate as the Err.. should only execute once. so, try break which I tested... this worked fine for you.. i tested....

提交回复
热议问题