Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 characters
         if (fgetc(fp) =='.')                     //before checking for .
            n++;       fclose(fp); }    return n; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote