0

Please explain the output...

Please Explain me ! main() { int c; while (( c = getchar() ) != EOF ) putchar(c); } My Expected result : i/p : abc o/p : a Computer result: i/p : abc o/p : abc ● If getchar() reads single character then why it is giving multiple characters ???

10th Aug 2018, 12:05 PM
Rahul Sahani
Rahul Sahani - avatar
2 ответов
+ 3
Because you use it in a while loop until the end of file is reached. So you get and print the chars one by one, but in the final output they appear glued together. You could add a print statement that prints a space or new line, then you see, that it is done for one letter by another
10th Aug 2018, 12:15 PM
Matthias
Matthias - avatar
+ 1
i advise not using get/putchar(), they're both pretty out of standard
10th Aug 2018, 12:16 PM
hinanawi
hinanawi - avatar