Hello to all,
I just want to know which characters represent EOF.
I am using TURBO C in WINDOWS.
Using code when I printed it shows -1 but in the output screen when I use it, it does not seem to be EOF.
Thanks for your support.
Printable View
Hello to all,
I just want to know which characters represent EOF.
I am using TURBO C in WINDOWS.
Using code when I printed it shows -1 but in the output screen when I use it, it does not seem to be EOF.
Thanks for your support.
EOF cannot be accurately represented by a char. Use an int to read characters if you need to test for EOF.
Quzah.
It doesn't matter. Just use EOF when you want to check against EOF. There's no need to ever, ever, ever know what EOF is, because the standard doesn't say exactly what it'll be.
But yeah, -1 is a common value implementors use ;)
If you're referring to how you type in an EOF, then pressing ctrl-z is usual for DOS/Windows.
Eg.
This is a line
ctrl-z
Would cause your program to see "This is a line\n" and then the EOF value
I'm using Dev-Cpp IDE with Mingw compiler and in my stdio.h I found that EOF is defined as:
but you shouldn't be concerned about it. What is important is to use it effectively, please look at the FAQ.Code:#define EOF (-1)
I think the end-of-file marker in files opened in text mode is represented by 0x1A (26) character.
Please execute this code:
where Test2.txt is in attachment.Code:int main(void)
{
FILE *fp;
int x, ret_val = 0;
fp = fopen ("Test2.txt", "r");
while ((ret_val = fscanf(fp, "%d",&x)) != EOF)
{
printf("%d ", x);
}
printf ("\n\n%d", ret_val);
return 0;
}
Tell me what is your output and which OS you're using!
It doesn't matter what mode you open it in. EOF canno...wait a second! I already answered this!Quote:
Originally Posted by Viorel
Quzah.
Some day, I swear I'm gonna write a libstdc with EOF as -0xE0F, just to throw all these idiots severely off track.
I think EOF = Ctrl+C (on Windows).
No. It doesn't. Not at all.Quote:
Originally Posted by X.Cyclop
This bad thread was so close to death, why try to revive it?