Things to remember when using getc() , getchar()..etc

Home Forums C-programming.. Things to remember when using getc() , getchar()..etc

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2466 Reply
    Humble
    Keymaster

    Lets look at man page of these functions:

           int fgetc(FILE *stream);
    
           int getc(FILE *stream);
    
           int getchar(void);
    
           int ungetc(int c, FILE *stream);
    
    
    Did you notice ? all these functions   fgetc(), getc() and getchar() ..etc return int .. That said, it return the character read as an unsigned char cast to an int or EOF on end of file or error.
    So always use an int for the result of getc and its family of functions, and check for EOF after the call; once you've verified that the result is not EOF, you can be sure that it will fit in a ‘char’ variable without loss of information. 
    
Viewing 1 post (of 1 total)
Reply To: Things to remember when using getc() , getchar()..etc
Your information: