Hacker News new | ask | show | jobs
by 634636346 1073 days ago
This (distinguishing -1 from a character value when char is unsigned) is one of the reasons character literals in C have type int instead of char (C++ changed them to char.) Note the return type of getchar().
1 comments

>fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.

>getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once.

>getchar() is equivalent to getc(stdin).