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.
Here is a version that uses integer to compare the value of getchar().
See this for more details.
- 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++
- return statement in C/C++ with Examples
- C function argument and return values
- Return values of printf() and scanf() in C/C++
- How to return multiple values from a function in C or C++?
- return statement vs exit() in main()
- How can I return multiple values from a function?
- Type Conversion in C
- Array Type Manipulation in C++
- What is data type of FILE in C ?