Answer to Exercise 1-6, page 17
Solution by Richard Heathfield
Verify that the expression getchar() != EOF is 0 or 1.
/* 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
* respond.
*/
#include <stdio.h>
int main(void)
{
printf("Press a key. ENTER would be nice :-)\n\n");
printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF);
return 0;
}
'The C Programming Language' 카테고리의 다른 글
Chapter 1 - A Tutorial Introduction 8 (0) | 2009.03.25 |
---|---|
Chapter 1 - A Tutorial Introduction 7 (0) | 2009.03.25 |
Chapter 1 - A Tutorial Introduction 5 (0) | 2009.03.25 |
Chapter 1 - A Tutorial Introduction 4 (0) | 2009.03.25 |
Chapter 1 - A Tutorial Introduction 3 (0) | 2009.03.25 |