0
#include <stdio.h>  

main(){ 
    int c;

    c = getchar();
    while (c!= EOF) 
    {
        putchar(c); 
        c = getchar();
    }
}

Example output:

1. Output: Hi there ^Z? 

           Hi there ->_ (loop doesn't end)
2. Output: Hi there?

           Hi there?
           ^Z (loop ends)

Why doesn't the loop end in the first case after reading ^Z but it ends in the second case?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
k_learner
  • 127
  • 1
  • 8
  • 5
    You're mixing up ^Z with the end-of-file condition. Pressing ^Z during a line causes the current line to be flushed and nothing more. Pressing it again causes end-of-file status to be set on the stream . – M.M Aug 16 '15 at 04:51
  • With ^Z, I would expect SIGTSTP to go to the process and that it would be backgrounded. I think you need a windows tag. – William Pursell Aug 16 '15 at 05:11
  • I read answers of Why do I require multiple EOF (CTRL+Z) characters? but I didn't get anything. I am new to programming and I also didn't understand any of the above explanations. :( – k_learner Aug 16 '15 at 14:44
  • Perhaps [this will make you understand](http://stackoverflow.com/questions/31261483/why-ctrl-z-does-not-trigger-eof?lq=1#comment50520540_31261483) – Spikatrix Aug 16 '15 at 15:38
  • Thank you for all the answers! – k_learner Aug 17 '15 at 01:05

0 Answers0