1-6/7
Quest: page 17
- Verify that the expression getchar() != EOF is 0 or 1
- Write a program to print the value of EOF
EOF definition
/* The value returned by fgetc and similar functions to indicate the
end of the file. */
#define EOF (-1)
eof
#include <stdio.h>
#include <stdlib.h>
int main() {
int c;
int status;
//print the value of EOF
printf("EOF: %d\n",EOF);
while (1) {
// status == 0 break the loop
// status == 1 continue read chars
status = (c = getchar()) != EOF;
printf("status: %d\n", status);
// NOTE: print out the status if u like
// printf("status: %d\n", status);
if (status == 0) {
break;
}
putchar(c);
}
return EXIT_SUCCESS;
}
thoughts:
- the value of EOF is a macro defined in stdlib.h on my machine which is a x86 GNU/linux.