Thread: diff btn getc() & getchar()

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Question diff btn getc() & getchar()

    What is the difference between getc() and getchar() functions?
    Anybody can explain with example?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > What is the difference between getc() and getchar() functions?
    Functionally - nothing

    getc might be a macro, whereas getchar is always a function

    getc will read from any FILE*, whereas getchar always reads from stdin

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I thought that getchar was normally implemented something like this...

    int getchar(void)
    {
    return getc(stdin);
    }

    wouldn't that make it the better candidate for a macro salem?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    putc() putchar()
    getc() getchar()

    The only difference, is the 'char' ones default to read from stdin, where as the 'c' ones require you specify a file stream. Usually if I recall correctly, a macro. Many 'functions' are implemented as macros.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Unregistered
    Guest
    incase of getchar()

    the program waits for a character
    followed by "enter" key

    but incase of getch()

    "enter" key is not needed .

    as soon as u press a character , the program
    continues .


    avinna

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    incase of getchar()

    the program waits for a character
    followed by "enter" key

    but incase of getch()

    "enter" key is not needed .

    as soon as u press a character , the program
    continues .


    avinna
    I believe this is incorrect. There is no ANSI standard for reading a single key STROKE. What you're seeing, unless I'm mistaken, is implementation specific. In C, because of the way input is handled, there is, unless changed, no ANSI method of grabbing a single keystroke. Your result is likely compiler specific.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Thumbs up

    Thank you very much for your replies. Now I have some idea about your discussion.

    -Kokila.

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