The Wayback Machine - https://web.archive.org/web/20231214203449/https://www.geeksforgeeks.org/g-fact-11/
Open In App
Related Articles

What is return type of getchar(), fgetc() and getc() ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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);
}


Here is a version that uses integer to compare the value of getchar().




int in;  
while ((in = getchar()) != EOF) 
{
   putchar(in);
}


See this for more details.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 May, 2017
Like Article
Save Article
Previous
Next
Similar Reads