Skip to content
Related Articles

Related Articles

Improve Article

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

  • Difficulty Level : Easy
  • Last Updated : 28 May, 2017

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.

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.

char ch;  /* May cause problems */  
while ((ch = getchar()) != EOF) 

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

int in;  
while ((in = getchar()) != EOF) 

See this for more details.

My Personal Notes arrow_drop_up
Recommended Articles
Page :