C Programming

Return type of getchar(), fgetc() and getc() ?

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) 

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

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

Recent Comments


For any feedback,email us at feedback@geeksforgeeks.org

Report a Bug

For any report or bug,email us at support@geeksforgeeks.org