Y
Yandos
Hello all,
I have maybe a trivial question, but I cannot think out what is wrong
How do i detect EOF correctly when i read from stdin? Am I doing it
wrong?
<pipetest.c>
#include <stdio.h>
int main(void) {
char ch;
while (!feof(stdin)) { // <-- EOF appears to be true when character 0x1A is on stdin
ch=getchar(); // <-- variable ch has value of 0xFF when 0x1A was on stdin
putchar(ch);
}
return(0);
}
<256.tmp>
contains values from 0 to 255
I compiled and run from cmd prompt: pipetest.exe < 256.tmp > out.tmp
<out.tmp>
00000000 00 01 02 03 04 05 06 07 08 09 0D 0A 0B 0C 0E 0F
00000010 10 11 12 13 14 15 16 17 18 19 FF
Why the program ended on 0x1A character and outputted FF instead?
How do I correctly write program which can be used with pipes? I use
free borland turbo c++ 1.01 compiler on windows xp.
Thanks anyone for kind help,
Y.
I have maybe a trivial question, but I cannot think out what is wrong
How do i detect EOF correctly when i read from stdin? Am I doing it
wrong?
<pipetest.c>
#include <stdio.h>
int main(void) {
char ch;
while (!feof(stdin)) { // <-- EOF appears to be true when character 0x1A is on stdin
ch=getchar(); // <-- variable ch has value of 0xFF when 0x1A was on stdin
putchar(ch);
}
return(0);
}
<256.tmp>
contains values from 0 to 255
I compiled and run from cmd prompt: pipetest.exe < 256.tmp > out.tmp
<out.tmp>
00000000 00 01 02 03 04 05 06 07 08 09 0D 0A 0B 0C 0E 0F
00000010 10 11 12 13 14 15 16 17 18 19 FF
Why the program ended on 0x1A character and outputted FF instead?
How do I correctly write program which can be used with pipes? I use
free borland turbo c++ 1.01 compiler on windows xp.
Thanks anyone for kind help,
Y.