Friday, 27 September 2013

getchar() unexpected behavior

getchar() unexpected behavior

char ch;
while((ch = getchar()) != EOF){
putchar(ch);
}
The above code, obviously enough, should copy my input. And it does work,
for basic ASCII text files.
However, if I send it a gif, in particular this one, but applicable to
most (http://www.cs.utexas.edu/~peterson/prog2/smile.gif), then when I
redirect stdin for the gif, and stdout to any file type, and run diff on
the original and the new one, errors galore. In this case, more than half
of the file isn't even processed, it simply quits. Any clues? I'd be
willing to switch off to another input/output functions, provided I can
input a byte at a time.

No comments:

Post a Comment