/* Examples of ways to detect end-of-file * (from standard input, end of file is generated by pressing -d) */ #include int main() { char ch; int retvalue; /* Use getchar() to obtain an input character -- upon detecting end-of-file, the value * EOF is stored in ch. */ for (;;) { ch = getchar(); if ( ch == EOF ) break; putchar( ch ); } /* for */ putchar( '\n' ); /* Use scanf() to read in characters. scanf() returns EOF upon detecting end-of-file. */ for (;;) { retvalue = scanf("%c", &ch); if ( retvalue == EOF ) break; printf( "%c", ch ); } /* for */ printf( "\n" ); } /* main */