Thread: getchar

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    11

    getchar

    I'm having some trouble understanding the exactly what this function does. I keep thinking of it as a scanf. Does anyone have a link to a tutorial that would help me understand this a bit better?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I'm having some trouble understanding the exactly what this function does
    Post a link to your online manual page, and indicate what is troubling you.

    It only does one thing, and returns two possible things - a character, or EOF.

    If you've understood anything at all of scanf (which is a far more complicated function), then getchar() should be a breeze.
    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.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    The name alone tells you exactly what it does. It gets a char.
    The only slightly confusing part of it is that it returns an int instead of a char, but that's just because EOF can't fit in a char.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    it getchar getcharacter from your keyboard to exit :P

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    It retreives a character from the standard input stream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getchar() problem
    By jlharrison in forum C Programming
    Replies: 6
    Last Post: 01-25-2006, 02:49 PM
  2. getchar buffer size
    By oncemyway in forum C Programming
    Replies: 3
    Last Post: 08-02-2005, 12:49 AM
  3. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-04-2004, 11:06 PM
  4. help with getchar lol
    By Taco Grande in forum C Programming
    Replies: 5
    Last Post: 03-18-2003, 09:25 PM
  5. Can anybody take a look at this?
    By TerryBogard in forum C Programming
    Replies: 10
    Last Post: 11-21-2002, 01:11 PM