while ((c = getchar()) != EOF) Not terminating

前端 未结 8 1062
一个人的身影
一个人的身影 2020-12-02 01:54

I\'ve been reading \"The C Programming Language\" and I got to this part of inputs and outputs.

I\'ve read other threads saying that the console doesn\'t recognize e

8条回答
  •  半阙折子戏
    2020-12-02 02:35

    Change the line

    // Buggy, you want calculate the # of '\n' in loop body,
    // so logically you shouldn't use it as a stop condition.
    while ((c = getchar()) != '\n')
    

    to

    while ((c = getchar()) != EOF)
    

    And try press Ctrl + C in your console window on Windows. It works on my platform which is running Win7.

    enter image description here

提交回复
热议问题