#include <stdio.h>
int main ()
{
FILE *fp;
int c;
fp = fopen("file.txt","r");
while(1)
{
c = fgetc(fp);
if( feof(fp) )
{
break ;
}
printf("%c", c);
}
fclose(fp);
return(0);
}
here in the code,the fgetc(fp) use the int as this return type,so why we use "printf("%c",c);" rather than "print("%d",c);"
In a printf
format string, %c
means “convert the int
argument to an unsigned char
and print the character it is the code for.”
%d
means “convert the int
argument to a decimal numeral and print that numeral.”