about EOF

This is a discussion on about EOF within the C Programming forums, part of the General Programming Boards category; I have used a while statement to test the EOF, if it sees EOF, the program should exit. I used ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    21

    Lightbulb about EOF

    I have used a while statement to test the EOF, if it sees EOF, the program should exit. I used command like this "my program<a.txt" and it worked, but when I ran it in the command prompt, I use control+Z to represent EOF, it did not work any more, thanks for any input!
    Code:
    char x;
     while((x=getchar())!=EOF)
    {
    //my code 
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Just a guess... but this is a windows system?

    CTRL-Z sending EOF is windows specific. On other systems, you should use CTRL-D.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    EOF cannot fit in a char. You'll have to use int as is expect.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    there is a detailed information about this in the FAQ Read this

    ssharish2005

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