difference between getchar(), getch(), and getc()

Home Forums C Programming difference between getchar(), getch(), and getc()

Viewing 4 reply threads
  • Author
    Posts
    • #1862
      Melisa
      Participant

      Hello everybody!
      This is my first post here in this forum. I like design. My question is: C language has so many functions for getting one character. GETCHAR, GETCH, GETC. Why is so many and what is the difference between these functions? I tried to read in the books but I am still confused. If somebody has good examples I would appreciate that.
      Thanks!

    • #3104
      msaqib
      Participant

      Amir welcome to MYCPLUS Online Community Forums. Thanks that you like the design of the website. Here is what you asked, hopefully you will understand. If there is anyone who can ad more to it I will appriciate.
      GETCHAR:
      getchar is a macro defined in (stdin), getchar returns the next character on the input stream stdin.
      It returns the character read, after converting it to an int without sign extension. If there is error reading the character or (and on end-of-file for getchar), it returns EOF.

      GETCH:
      getch gets a character from console but does not echo ( write ) to the screen. It reads a single character directly from the keyboard, without echoing
      to the screen. getche reads a single character from the keyboard and echoes it to the current text window, using direct video or BIOS. Both functions return the character read from the keyboard.
      Declaration:

      GETC:
      getc is a macro that gets one character from a stream. It returns the next character on the given input stream and increments the stream’s file pointer to point to the next character.It returns the character read, after converting it to an int without sign extension. If there is error (and on end-of-file for getc), both functions return EOF.

    • #3105
      Melisa
      Participant

      Thanks msaqib, this was very useful for me.

    • #3106
      prasanna
      Participant

      If you open the Torbo C++ Compiler help it will give you the following details about these functions.
      getchar is a macro defined as getc(stdin) getchar returns the next character on the input stream stdin.
      Return Value:
      On success
      – getchar returns the character read, after converting it to an int without sign extension.
      On error (and on end-of-file for getchar), both macros return EOF.

      getc returns the next character on the given input stream and increments the stream’s file pointer to point to the next character.
      Return Value:
      On success
      – getc returns the character read, after converting it to an int without sign extension.
      On error (and on end-of-file for getc), both functions return EOF.

      I hope you can now wel understand this.

       

    • #3107
      VIGNESH
      Participant

      thank you very msaqib and guru for clearing my doubt.
      genetic.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Share
Tweet
Share
Pin