What is the difference between get(), gets(), getch(), getche() and getchar()?
char* gets(char* string) from <stdio.h> - reads characters from the standard input (stdin) to the string
& until a newline ('\n') if reached (when user presses 'Enter').
& The string array must be big enough to store the line you want to read.
& Returns the passed string parameter if read operation succeeded
& or NULL if an error happened or end of file (eof) reached.
int getc(FILE* file) from <stdio.h> - reads next character from the file.
& The input argument is an opened file pointer (see fopen function).
int getchar() from <stdio.h> - reads and returns a single character from the stdin.
We can notice that getc(stdin) and getchar() do the same thing.
int getch() from <conio.h> - it works the same as getchar() but doesn't display the entered character
(doesn't output it to the stdout). Is commonly used to delay the program before exit.
int getche() from <conio.h> - a getchar() alternative.
The last two functions are nonstandard.
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++