Thread: End of File

  1. #1
    Unregistered
    Guest

    End of File

    I'm sure you guys have had this question before... but how do you reach EOF in a statement such as...

    while (getchar() != EOF)
    do something;

    I'm working on the exercises in K&R that want to Verify the expression getchar() != EOF is 0 or 1, and how to write a program to print the value of EOF. All the other books I've read started by teaching printf/scanf so this is a little different.

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    i haven't understood the question... but...

    why while (getchar() != EOF)

    and not while (c = getchar() != EOF)

    you need something to get values from the file to(c)!!!
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    197

    ASCII-charakter

    Hi!

    Thereīs a ASCII-character called EOF, but I donīt know its number.

    klausi
    When I close my eyes nobody can see me...

  4. #4
    free(me);
    Join Date
    Oct 2001
    Location
    Santo Domingo, DN, Dominican Republic
    Posts
    98

    Exclamation ...

    The value of EOF depends on your lib i think. Or is it machine-dependant? I can't remember. K&R says it some where.

    Anyways, in Windows console just press Ctrl-Z. That'll be EOF and your while loop will terminate.

    On my machine printf("%d", EOF); returns -1. Try it on yours and see.

    adios,
    biterman.

    PS: I'm sure you'll find the definition for EOF in your stdio.h file.
    Do you know how contemptous they are of you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  4. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  5. checking for end of file
    By linucksrox in forum C Programming
    Replies: 7
    Last Post: 06-01-2004, 01:41 AM