return value of getChar()

This is a discussion on return value of getChar() within the C Programming forums, part of the General Programming Boards category; what is the return value of getChar method when it is called after end of file has been reached ... ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    1

    return value of getChar()

    what is the return value of getChar method when it is called after end of file has been reached ... as in it has once returned EOF and we call it again wht will be the value is it still EOF or an error condition is there

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    getchar() dosn't read from a file it reads from a standard input stream - keyboard -

    ssharish2005

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by ssharish2005
    getchar() dosn't read from a file it reads from a standard input stream - keyboard -

    ssharish2005
    true but getchar() can still return EOF.
    consider this example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
        int c;
        while ( (c = getchar()) != EOF ) {
            printf("%c", c);
        }
    }
    if you call it using input redirection
    Code:
    testgetch < testgetch.c
    >> what is the return value of getChar method when it is called after end of file has been reached ... as in it has once returned EOF and we call it again wht will be the value is it still EOF or an error condition is there
    getchar() will continue to return EOF.
    Kurt

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    yes u are right Zuk my bad. we do that for clearing the input buffer somewhere in program as well isn't it. sorry i dint realize at that time.

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 11:00 PM
  2. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 11:40 AM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21