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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Difference between getc(), getchar(), getch() and getche()
- Implicit return type int in C
- EOF, getc() and feof() in C
- fgetc() and fputc() in C
- Difference between Type Casting and Type Conversion
- What does main() return in C and C++?
- return statement in C/C++ with Examples
- Return from void functions in C++
- C function argument and return values
- How can I return multiple values from a function?
- Return values of printf() and scanf() in C/C++
- return statement vs exit() in main()
- How to return multiple values from a function in C or C++?
- Type Conversion in C
- What is the size_t data type in C?
- Is there any need of "long" data type in C and C++?
- What is data type of FILE in C ?
- Array Type Manipulation in C++
- Implicit Type Conversion in C with Examples
- Data Type Ranges and their macros in C++