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

Why wont this compile? #include <stdio.h> #include <stdlib.h> #include \"bubble.

ID: 3747135 • Letter: W

Question

Why wont this compile?

#include <stdio.h>

#include <stdlib.h>

#include "bubble.h"

struct classStats {

float mean;

float min;

float max;

float median;

char* name;

};

int main() {

FILE *fptr;

int i;

fptr = fopen("grades", "r");

struct student_info *studentScore[19];

struct classStats stats;

fscanf(fptr, "%s", stats.name);

if (fptr == NULL)

{

printf("Error opening file ");

return 0;

}

float sum = 0;

for (i = 0;i<19;i++) {

studentScore[i] = (struct student *)malloc(sizeof(struct student_info));

studentScore[i]->first = (char *)malloc(sizeof(char) * 20);

studentScore[i]->last = (char *)malloc(sizeof(char) * 20);

fscanf(fptr, "%s%s%d%d%d", studentScore[i]->first, studentScore[i]->last, &studentScore[i]->exam1,

&studentScore[i]->exam2, &studentScore[i]->exam3);

}

fclose(fptr);

bubble(studentScore,19);

stats.max = studentScore[18]->mean;

stats.min = studentScore[0]->mean;

stats.mean = sum / 19;

stats.median = studentScore[19 / 2]->mean;

printf("%s MEAN: %.2f MIN: %.2f MAX: %.2f MEDIAN: %.2f ", stats.name, stats.mean,

stats.min, stats.max, stats.median);

for (i = 0; i < 19; i++) {

printf("%12s %12s %.2f ", studentScore[i]->first, studentScore[i]->last, studentScore[i]->mean);

}

return 0;

}

Explanation / Answer

Hi Sir, couple of things and references are missing in your source code, that you need to add to your code for the fix:-

1. struct student_info *studentScore[19] - Where is this Structure student_info written in the code. There is no reference to this struct type. You need to add/create a new Structure of type student_info

2. fptr = fopen("grades", "r"); = Make sure you have the grades.txt in the same folder in which .c file exists. Moreover it should be grades.txt not simply grades.

3. struct student * = Again struct student is missing in this code. Please add/create this struct student

4. #include "bubble.h" - You have included this header file, make sure bubble.h header file is also present in the same folder structure where all c files are located

5. bubble(studentScore,19) - Make sure "bubble.h" header file contains bubble() function and this is how the link to the function can be made.

Rest of the C program is fine.

Plaese let me know in case of any clarifications required. Thanks!

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