Thread: Getchar,putchar

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    14

    Getchar,putchar

    I need an explanation about these functions,ive been reading the K&R book and came across this,they explained these functions a little bit wierd ,so i really need help on this.And no,i dont need wiki answers,just need someone too type out a bit of theory.Thanks very much.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Getchar gets a character (from the keyboard buffer).

    Putchar puts a character (to the screen).

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    14
    Can you give me an example of the usage?

  4. #4
    Banned
    Join Date
    Aug 2011
    Location
    Ghaziabad, India, India
    Posts
    48
    Quote Originally Posted by tabstop View Post
    Getchar gets a character (from the keyboard buffer).

    Putchar puts a character (to the screen).
    May be In case of File too .

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    @Vxyz: getchar and putchar cannot be used for files (except in the case of I/O indirection, but that's up to the operating system, not our C program).

    Code:
    char c = getchar();
    putchar(c);
    Technically char c should be int c, so that getchar can return EOF in case of total input failure.

  6. #6
    Banned
    Join Date
    Aug 2011
    Location
    Ghaziabad, India, India
    Posts
    48
    Quote Originally Posted by tabstop View Post
    @Vxyz: getchar and putchar cannot be used for files (except in the case of I/O indirection, but that's up to the operating system, not our C program).

    Code:
    char c = getchar();
    putchar(c);
    Technically char c should be int c, so that getchar can return EOF in case of total input failure.
    Really .... ?

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Vxyz View Post
    May be In case of File too .
    No getchar() and putchar() DO NOT operate on files.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Filster View Post
    I need an explanation about these functions,ive been reading the K&R book and came across this,they explained these functions a little bit wierd ,so i really need help on this.And no,i dont need wiki answers,just need someone too type out a bit of theory.Thanks very much.
    A little advice, my friend... When in doubt look it up most C compilers come with libary documentation that is very complete, usually including examples of correct usage. Yes a forum like this is a good place if you're stuck on a project (really stuck, not lazy stuck) but we are not the "C library support desk".

    One of a programmer's primary skills is the ability to look stuff up... in fact, you won't write any program larger than a training exercise without repeatedly looking up function calls in the library documentation of your compiler... Now is the time to cultivate this skill.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Vxyz View Post
    Really .... ?
    Yes... really. Now please stop jumping into every thread with stupid questions.

    EDIT... Welcome to my ignore list!
    Last edited by CommonTater; 08-03-2011 at 10:09 AM.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Vxyz View Post
    Really .... ?
    Yes really. What are you concerned about? (Note that getchar is a different function than fgetc, which does work on files.)

    EDIT: Jinx!

  11. #11
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Filster View Post
    I need an explanation about these functions,ive been reading the K&R book and came across this,
    Translation: I have been holding the K&R Book and hoping to learn via osmosis

    Quote Originally Posted by Filster View Post
    they explained these functions a little bit wierd ,so i really need help on this.
    Translation: I am too lazy to use google

    Quote Originally Posted by Filster View Post
    And no,i dont need wiki answers,
    Translation: Even if I used google, I am too lazy to read

    Quote Originally Posted by Filster View Post
    just need someone too type out a bit of theory.Thanks very much.
    Translation: Will someone hold my hand and teach me how to program step by step?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Translation: I have been holding the K&R Book and hoping to learn via osmosis
    "I've been looking that this for 12 seconds and it doesn't make any sense at all"
    "Did you try actually reading the page?"

  13. #13
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by CommonTater View Post
    "I've been looking that this for 12 seconds and it doesn't make any sense at all"
    "Did you try actually reading the page?"
    LOL....I imagine that is how most of the OPs conversations go.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  14. #14
    Banned
    Join Date
    Aug 2011
    Location
    Ghaziabad, India, India
    Posts
    48
    Quote Originally Posted by CommonTater View Post
    Yes... really. Now please stop jumping into every thread with stupid questions.

    EDIT... Welcome to my ignore list!
    I am not here for asking such stupidity . . . i am just giving you the way to just Rethink why This is not so ?
    I think You are not taking this seriously. Be Wash your face and I don't care about your ignore list.

  15. #15
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Vxyz View Post
    I am not here for asking such stupidity . . . i am just giving you the way to just Rethink why This is not so ?
    I think You are not taking this seriously. Be Wash your face and I don't care about your ignore list.
    This isn't a social networking site. Stop trolling.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getchar() and putchar()
    By kawaikx15 in forum C Programming
    Replies: 5
    Last Post: 04-13-2011, 11:02 AM
  2. getchar putchar
    By chess2009 in forum C Programming
    Replies: 7
    Last Post: 03-06-2011, 02:44 AM
  3. getchar and putchar
    By BEN10 in forum C Programming
    Replies: 4
    Last Post: 03-11-2009, 10:29 PM
  4. need help please! getchar, putchar, etc.
    By sue in forum C Programming
    Replies: 1
    Last Post: 03-21-2003, 08:40 PM