Find the error in the following function and show how to fixit. int count_period
ID: 3615380 • 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
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) //reading 2 charactersif (fgetc(fp) =='.') //before checking for .
n++; fclose(fp); } return n; }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.