The Wayback Machine - https://web.archive.org/web/20230512155103/https://www.geeksforgeeks.org/g-fact-11/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

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

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.

My Personal Notes arrow_drop_up
Last Updated : 28 May, 2017
Like Article
Save Article
Similar Reads