Thread: EOF

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    32

    Lightbulb EOF

    Code:
    main()
    {
    int c;
    c = getchar();
    while (c != EOF) {
    putchar(c);
    c = getchar();
    }
    }
    
    Please exp above pgm. what the while (c != EOF) statement tells?

  2. #2
    Registered User
    Join Date
    Sep 2010
    Posts
    25

    It means it's time for finals in Comp Sci 101!

    Code:
    "while (condition){ perform task }"
    means: while a given condition exists, perform { the task enclosed in brackets }.

    Code:
    " . . . (c != EOF) . . . "
    Means: c is not equal to End Of File signal (usually a keystroke like [CNTRL][D]).

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Run the program.

    Type in some characters and newlines, and observe.

    When you get bored AFTER pressing enter, try one of these
    - On Unix/Linux systems, press CTRL-D
    - On DOS/Windows, press CTRL-Z
    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.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    32
    I used eclipse s/w to compile this program. But here is no effect when I press CTRL-D or CTRL-Z.

  5. #5
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Salem View Post
    Run the program.

    Type in some characters and newlines, and observe.

    When you get bored AFTER pressing enter, try one of these
    - On Unix/Linux systems, press CTRL-D
    - On DOS/Windows, press CTRL-Z
    Correction, on DOS/Windows, press [Ctrl]-Z followed by [Enter] at the beginning of a line.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    32

    Lightbulb

    Thanks all. It's working fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. while ((c = getchar()) != EOF), AND cntrl z
    By Roger in forum C Programming
    Replies: 8
    Last Post: 10-21-2009, 09:25 PM
  2. EOF Explanation Anybody?
    By blackcell in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 09:09 PM
  3. EOF or not EOF?
    By CornedBee in forum Linux Programming
    Replies: 2
    Last Post: 09-14-2007, 02:25 PM
  4. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  5. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM