Find the error in the following function and show how to fixit. int count_period
ID: 3615381 • Letter: F
Question
Find the error in the following function and show how to fixit. int count_periods(const char *filename) { FILE *fp; int n = 0; if((fp = fopen(filename, "r")) !=NULL) { while (fgetc(fp) != EOF) if (fgetc(fp) == '.') n++; fclose(fp); } return n; } Find the error in the following function and show how to fixit. int count_periods(const char *filename) { FILE *fp; int n = 0; if((fp = fopen(filename, "r")) !=NULL) { while (fgetc(fp) != EOF) if (fgetc(fp) == '.') n++; fclose(fp); } return n; }Explanation / Answer
Please rate - thanksFind the error in the following function and show how to fixit.
int count_periods(const char *filename) { FILE *fp; int n = 0; if((fp = fopen(filename, "r")) !=NULL) { while (fgetc(fp) != EOF) //reading 2 characters
if (fgetc(fp) =='.') //before checking for .
n++; fclose(fp); } return n; }