Exercise 1-7 (Print EOF)
Chapter_1 Exercise_1-6 | copyEOF Exercise_1-8 |
Exercise 1-7 K&R, p. 17
Exercise 1-7. Write a program to print the value of EOF.
eof.c download
#include <stdio.h> // for putchar(), printf(), EOF
// print the value of EOF, as defined by stdio.h
int main()
{
// putchar(EOF); putchar('\n'); // EOF == -1 is converted to max char 255
// putchar(255); putchar('\n'); // (modulo 2 arithmetic)
printf("EOF = %d\n", EOF); // print as integer
}
/*
gcc -E eof.c // preprocessing
# 5 "eof.c"
int main()
{
printf("EOF = %d\n",
# 9 "eof.c" 3 4
(-1) // EOF macro replaced (expanded)
# 9 "eof.c"
);
gcc eof.c -o eof // compiling
./eof
EOF = -1
*/
Note:
EOF is printed as an integer,
not as a character, as in
putchar(EOF); putchar('\n');
The argument of putchar()
is an
unsigned char,
varying from 0 to 255, see
Exercise_2-1.
Chapter_1 Exercise_1-6 | BACK_TO_TOP | copyEOF Exercise_1-8 |
Comments
Post a Comment