What is return type of getchar(), fgetc() and getc() ?
In C, return type of getchar(), fgetc() and getc() is int (not char). So it is recommended to assign the returned values of these functions to an integer type variable.
char ch; /* May cause problems */ while ((ch = getchar()) != EOF) { putchar(ch); } |
chevron_right
filter_none
Here is a version that uses integer to compare the value of getchar().
int in; while ((in = getchar()) != EOF) { putchar(in); } |
chevron_right
filter_none
See this for more details.
Recommended Posts:
- Difference between getc(), getchar(), getch() and getche()
- Implicit return type int in C
- EOF, getc() and feof() in C
- fgetc() and fputc() in C
- What does main() return in C and C++?
- Return from void functions in C++
- C function argument and return values
- How to return multiple values from a function in C or C++?
- How can I return multiple values from a function?
- return statement vs exit() in main()
- Return values of printf() and scanf() in C/C++
- Type Conversion in C
- Array Type Manipulation in C++
- What is the size_t data type in C?
- Is there any need of "long" data type in C and C++?



