I wanted to learn fgetc, so I did a search.
This was the first result:
C library function - fgetc() (tutorialspoint.com)
It has this code:
#include <stdio.h>
int main () {
FILE *fp;
int c;
int n = 0;
fp = fopen("file.txt","r");
if(fp == NULL) {
perror("Error in opening file");
return(-1);
} do {
c = fgetc(fp);
if( feof(fp) ) {
break ;
}
printf("%c", c);
} while(1);
fclose(fp);
return(0);
}
Am I missing something or isn't this code buggy? If file.txt is one character, won't it break before printing the character?
Thank you.