fgetc() returns an int, right? Then why is it I can assign c, a character, to the result of fgetc(fp)? ...It doesn't make any sense to me.
Code:#include <stdio.h> int main(void){ FILE *fp = fopen("myFile.txt","r"); if(!fp){ printf("Error opening file."); } char c; int n=0; while(c!=EOF){ c = fgetc(fp); printf("%c",c); if(c == '$'){ n++; } } printf("Your file has %d$s.\n",n); getchar(); return 0; }



LinkBack URL
About LinkBacks


