What is the difference between get(), gets(), getch(), getche() and getchar()?
1
Expert's answer
2013-01-30T07:31:02-0500
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.
Comments
Leave a comment