What is the difference between the functions getch, getchar, scanf in the C programming language?

  • 2
    Well, it is, in the title, for example. - nitrocaster
  • Actually, these are functions of the standard library, not the language itself. And in the standard library C there is no and never was a getch function. - AnT

2 answers 2

scanf - formatted input. It can read several values ​​of different types and formats at once (relevant for floating-point numbers)

getchar - reads one character from standard input (console). If the character is EOF, then sets the end of input flag for standard input ( stdin ).

getch - just reads one character from the console. Not included in the standard, implementations for different compilers may vary. MSDN recommends using _getch from the standard.

  • 2
    > Petrosyan. It is not clear why ask a question, the answer to which you can google in a minute. - nitrocaster
  • one
    If the question about the difference between getchar and getch still has some kind of logic to it, then the question about the difference of scanf from them for my taste is quite strange. The argument list is different, the return value is different, but in general everything else. - VladD 1:51 pm
  • 2
    @Flammable, it is not clear why petrosyanit in response to a question, the answer to which you can google in a minute. - etki 2:13 pm
  • one
    @Etki: because the author of the question was too lazy to google for a minute? - VladD
  • one
    "MSDN recommends using _getch from the standard." But in the standard there is neither getch nor _getch . - AnT

About getch and getchar .

But the differences with scanf look in the documentation.