Problem with example 1.5.2 in K&R book on C

前端 未结 4 651
耶瑟儿~
耶瑟儿~ 2020-12-17 01:47

I\'m teaching myself C with K&R and am stumped by one of the examples in the book. I compile the code exactly as it is written in the example but it does not do what th

4条回答
  •  旧时难觅i
    2020-12-17 02:11

    It would also be worth noting that Ctrl + z (which will appear as ^Z in the console) cannot simply be entered anywhere in the console input; you must enter it as the first input of your final line of string/text/characters. E.G

    Picture of initial input Ctrl + z

    As you can see in this example I typed in random text and after each line ended, I pressed enter. NOW THIS IS IMPORTANT!!! When you press enter on the final line it will invoke the EOF (End-of-File) and you'll get the rest of the code executing like it was originally intended to happen.

    Fully executed code

    Note:

    • Even though Ctrl + z appears as ^Z, it is not counted as a character by the program however many times you press it.
    • Also characters after ctrl+z are not counted.
    • Enter is counted by this program

    Source: EOF in Windows command prompt doesn't terminate input stream

提交回复
热议问题