Hey, I am currently working through Kernighan & Ritchie's 'The C Programming Language,' and have been doing the exercises they list at the end of the sections where you have to modify the programs or come up with your own etc..
Anyway, there are a couple that have been stumping me, (I am not in a hurry to give up on them, as I think the hard ones are the good way to learn), so I took a look around on the web to see if I could find some help, and there is a site that gives a lot of the answers to the exercises. Here is one of their answers (which does not seem to work right. It compiles ok, but does not seem to do what I want it to, or even what is listed in the comments at the beginning of the code):
I am pretty new to C, but as I looked at this, I can't see how the second printf statement could work, if there is no variable initialised.
/* This program prompts for input, and then captures a character
* from the keyboard. If EOF is signalled (typically through a
* control-D or control-Z character, though not necessarily),
* the program prints 0. Otherwise, it prints 1.
* If your input stream is buffered (and it probably is), then
* you will need to press the ENTER key before the program will
printf("Press a key. ENTER would be nice :-)\n\n");
printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF);