... ok theres this one exercise to write a program to show the value of EOF.. unfortunately i tried many different ways but all it came out in dev c++ is 3 "smiley faces"?? is that suppose to be a 0 or what , i have no idea.
... ok theres this one exercise to write a program to show the value of EOF.. unfortunately i tried many different ways but all it came out in dev c++ is 3 "smiley faces"?? is that suppose to be a 0 or what , i have no idea.
Code:printf("%d\n", EOF);Of course, the value of EOF is irrelevant to real programming. All you need to know, as a programmer, is that it fits within an int.itsme@itsme:~/C$ grep -n "define EOF" /usr/include/*.h
/usr/include/libio.h:90:# define EOF (-1)
/usr/include/stdio.h:112:# define EOF (-1)
itsme@itsme:~/C$
Last edited by itsme86; 07-06-2006 at 12:39 AM.
If you understand what you're doing, you're not learning anything.
EOF isn't one set value you can test for. You should only ever test EOF against the macro EOF. EOF doesn't have to be one specific number. It could be -1234 on one compiler, -1 on another, or what not, and all would be conforming to the ANSI C definition of it. Thus, you should only ever test EOF against the macro EOF.
Quzah.
Hope is the first step on the road to disappointment.
use feof() to determine if a current stream position indicator is at EOF. its prototype:
note that this does not return the value of EOF, it returns nonzero if EOF has been encountered in the last input operation on the stream, 0 if it hasn't.Code:int feof(FILE *stream);
Last edited by Bleech; 07-06-2006 at 12:38 AM.
Intel Core 2 Quad Q6600 @ 2.40 GHz
3072 MB PC2-5300 DDR2
2 x 320 GB SATA (640 GB)
NVIDIA GeForce 8400GS 256 MB PCI-E
feof() is useless most of the time, since the standard I/O functions return a special value (usually EOF or NULL) when EOF has been reached.
The concept that feof() only returns true after a read attempt at EOF has occured seems to confuse most beginners as well. This is evident by the fact that so many beginners try to incorrectly control a read loop using feof(). There's even an FAQ about it.
It's much simpler to just check the return value of whatever standard read function you're using.
Last edited by itsme86; 07-06-2006 at 12:38 AM.
If you understand what you're doing, you're not learning anything.
>EOF doesn't have to be one specific number.
Well, it *does* have to be negative. But other than that, anything that fits within an int is acceptable. Though -1 seems to be a popular choice.
My best code is written with the delete key.
That's what happens when you try to print the character 0 or 1. You should use the printf format specifier %d if you want to see what your compiler uses for EOF, not %c.i tried many different ways but all it came out in dev c++ is 3 "smiley faces"??
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.