Thread: getchar() question

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    37

    getchar() question

    I have seen in different text/source code that a variable that will get the getchar() result is declared in some code listings as int and in other code listings as char.
    Which is the proper approach?
    Thank you.

  2. #2
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by skiabox View Post
    I have seen in different text/source code that a variable that will get the getchar() result is declared in some code listings as int and in other code listings as char.
    Which is the proper approach?
    Thank you.
    Hi! Here's a start to the proper approach:

    Code:
    int main(void)
    {
            // Your code here
    
    
           return 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    The type of variable that stores the result of getchar should match the return type of getchar (int). Read through the documentation here for the details: getchar(3): input of char/strings - Linux man page.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I don't understand "while (getchar() != '\n');"
    By valedor in forum C++ Programming
    Replies: 13
    Last Post: 09-08-2009, 05:12 PM
  2. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  3. noob question
    By gillypie in forum C Programming
    Replies: 21
    Last Post: 09-04-2007, 07:49 AM
  4. getchar() problem
    By jlharrison in forum C Programming
    Replies: 6
    Last Post: 01-25-2006, 02:49 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM