Whats the value of EOF?

This is a discussion on Whats the value of EOF? within the C Programming forums, part of the General Programming Boards category; ... ok theres this one exercise to write a program to show the value of EOF.. unfortunately i tried many ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    20

    Whats the value of EOF?

    ... 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.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,656
    EOF is a macro to some integer.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Code:
    printf("%d\n", EOF);
    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$
    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.
    Last edited by itsme86; 07-06-2006 at 12:39 AM.
    If you understand what you're doing, you're not learning anything.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  5. #5
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    use feof() to determine if a current stream position indicator is at EOF. its prototype:

    Code:
    int feof(FILE *stream);
    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.
    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

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    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.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    i tried many different ways but all it came out in dev c++ is 3 "smiley faces"??
    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.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EOF Explanation Anybody?
    By blackcell in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 08:09 PM
  2. EOF or not EOF?
    By CornedBee in forum Linux Programming
    Replies: 2
    Last Post: 09-14-2007, 02:25 PM
  3. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  4. whats the deal with EOF really ???
    By gemini_shooter in forum C Programming
    Replies: 7
    Last Post: 03-06-2005, 03:04 PM
  5. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21