I'm having a problem understanding this seemingly simple piece of code, that is represented in the book "Advanced programming in UNIX environment":
include "apue.h"
int main (void)
{
int c;
while((c = getc(stdin)) != EOF)
if(putc(c, stdout) == EOF) //this bugs me
err_sys("output error");
if(ferror(stdin))
err_sys("input error");
exit(0);
}
The book states that this program copies standard input to standard output, using getc and putc. The part i understand is, that the program prints "output error", when there's no character to output, but i don't see the code anywhere that actually transfers the input to the output (it seems that the if loop is missing the else block, that actually outputs the character).
Maybe there is some fundamental thing that i don't recognize here?
Aucun commentaire:
Enregistrer un commentaire