Code:main() { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } } Please exp above pgm. what the while (c != EOF) statement tells?
Code:main() { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } } Please exp above pgm. what the while (c != EOF) statement tells?
means: while a given condition exists, perform { the task enclosed in brackets }.Code:"while (condition){ perform task }"
Means: c is not equal to End Of File signal (usually a keystroke like [CNTRL][D]).Code:" . . . (c != EOF) . . . "
Run the program.
Type in some characters and newlines, and observe.
When you get bored AFTER pressing enter, try one of these
- On Unix/Linux systems, press CTRL-D
- On DOS/Windows, press CTRL-Z
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I used eclipse s/w to compile this program. But here is no effect when I press CTRL-D or CTRL-Z.
Thanks all. It's working fine.