Despite its name, getc returns int , not char , so that it can represent all possible char values ββand, in addition, EOF (end of file). If getc returned char , there would be no way to indicate the end of the file without using one of values ββthat could be in the file.
So, in order to fix your code, you must first modify the char c; declaration char c; to int c; so that he can hold the EOF token when it is returned. Then you must also change the condition of the while loop to check EOF instead of NULL .
You can also call feof(fr) to check the end of the file separately from reading the character. If you have done this, you can leave c as a char , but you will have to call feof() after you read this character, but before you print it, and use break to exit the loop.
benzado
source share