The following simple program counts the number of words from the stdin (my keyboard). When i press CTR+Z it should stop and present the results. I'm using Windows 10.
If i run the program the ctr+z does NOT work regardless how many times i press it. Could you please help me understand what is happening in the background and the cntr+z does not comply?
I do not want the code that solves the problem, i know that, i just can't figure out
what is happening...and fails. The debugging of this issue i try to understand.
Note that getchar() does not return until you hit <ENTER> or you hit CTRL+Z so this can be confusing the issue. Your program will wait on line 8 until you enter the first line of text and hit <ENTER> Then your program will go into the second loop and process all the characters you just entered until it gets to \n. At that point your program will go back to line 8 and start over. Probably not what you wanted to do. But that is just a side issue.
If you just enter CTRL+Z on the line all by itself then your program should exit. If it does not then I suspect something strange is going on with your IDE tools or OS or some such.
I canceled the solved.
I test the code with 2 printf() . I run it and it falls into a forever loop inside the second while statement. I think the while statement has the condition (ch!=EOF) line 14 ,so it should stop when i press ctr+z. Am i missing something here?