How do I initiate EOF?

This is a discussion on How do I initiate EOF? within the C Programming forums, part of the General Programming Boards category; I just started "The ANSI C Programming Language" and some of they use EOF but dont tell you how to ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    3

    How do I initiate EOF?

    I just started "The ANSI C Programming Language" and some of they use EOF but dont tell you how to use it after you build your program...

    heres the source if it makes a difference:
    Code:
    /* Count characters in input ver 1 */
    #include <stdio.h>
    
    int main() {
        
        long c;
        c = 0;
        
        while (getchar() != EOF)
                ++c;
                
        printf ("%ld\n", c);
        
        return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    At the start of a newline, press
    CTRL-D if you're on Linux
    CTRL-Z if you're on DOS or a win32 console.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    EOF basicly translate to END OF FILE. It is an old macro name and a way of breaking
    a loop in a program. You can manually execute EOF by pressing ^Z in the program to end the loop. In general, try to find another way to end the loop.

    Code:
    while ( i < 10 )
    {
       i++;
    
       if ( i == 5 )
          break;
    }

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    3
    How would this work on mac osx I figured it would be the same as linux, but it wont end the loop

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    I use windows, not Mac or Liunix. You could try a google or search the FAQ's for an answer. I would of thought break would end the loop. The snippett above was a sample, not a complete program. Did you get any errors?

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    EDIT: You are also missing braces around your while loop

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    3
    I tried something simillar to your snippett where there would be a break but after I tried that It printed out a value not equal to what it should be. Ie the program is supposed to return the number of characters in the loop

    edit you dont need braces in this case because ++c; is the only thing going on
    Last edited by vroemer; 11-05-2006 at 02:25 PM.

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