Thread: Eof?

  1. #1


    Is EOF the same thing as NULL?

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    no, EOF is "end of file" and it's usually defined as -1 (while NULL is usually 0)

  3. #3
    Well in something like-

    #include <iostream>
    #include <string>
    int main()
    	string c;
    	std::cout << "Type in your sentence: ";
    	while ((c = getchar()) != EOF)
    		std::cout << c;
    	return 0;
    what else can be used instead of EOF?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >what else can be used instead of EOF?
    In this case anything, your code shouldn't compile. But assuming we changed it to something more reasonable:
    #include <iostream>
    #include <cstdio>
    int main()
      int c;
      std::cout<<"Type in your sentence: ";
      while ( ( c = getchar() ) != EOF )
        std::cout<< char ( c );
    You can replace EOF with any valid character returned by getchar. In this case a good test is for '\n' so that the loop stops after a single line.

    My best code is written with the delete key.

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, 09: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, 04: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