Amelia G.

asked • 06/21/22

Need assistance with C code, not running

#include <stdio.h>

struct students{ //struct student

char FirstName; //String to store first name

char secondName; //string to store second name

int ID; //student ID

float GPA; //student gpa

char Progression; //Studnet progression status

};

int main()

{


struct students sp[10] ;


FILE *fp;

fp = fopen("YearOneICT.txt", "r");


if (fp == NULL)

{

printf("File not found");

return 0;

}


int students[10]; // array to h

int i = 0;


while (fscanf(fp, "%s %s %d %f", &sp[i].FirstName, &sp[i].secondName, &sp[i].ID, &sp[i].GPA) != EOF)

{

i++;

}

fclose(fp);


int student[10]; // array to h

for(int i =0;i<10;i++){

if(sp[i].GPA>3.8) {sp[i].Progression = 'H'; sp[i] = 1;} //Decide studens progression depeding on their GPA


else

if(sp[i].GPA>=2.0 && sp[i].GPA<=3.8) sp[i].Progression = 'N'; sp[i] = 0;}


else {sp[i].Progression = 'P'; sp[i] = -1;}



FILE *fp1;

fp1 = fopen("ClassSummary.txt", "w");


if (fp1 == NULL)

{

printf("File not found");

return 0;

}

fprintf(fp1,"Honours List\n");

for(int i =0;i<10;i++){


if(sp[i].Progression=='H'){

fprintf(fp1, "%s %s %d %f", sp[i].FirstName, sp[i].secondName, sp[i].ID, sp[i].GPA));

printf("%s %s %d %f", sp[i].FirstName, sp[i].secondName, sp[i].ID, sp[i].GPA);


}

}

fprintf(fp1,"Progessing Normally\n");

for(int i =0;i<10;i++){


if(sp[i]=='N'){

fprintf(fp1, "%s %s %d %f", sp[i].FirstName, sp[i].secondName, sp[i].ID, sp[i].GPA));

printf("%s %s %d %f", sp[i].FirstName, sp[i].secondName, sp[i].ID, sp[i].GPA);

}

}

fprintf(fp1,"Academic Probation\n");

for(int i =0;i<10;i++){


if(sp[i].Progression=='P'){

fprintf(fp1, "%s %s %d %f", sp[i].FirstName, sp[i].secondName, sp[i].ID, sp[i].GPA);

printf("%s %s %d %f", sp[i].FirstName, sp[i].secondName, sp[i].ID, sp[i].GPA);

}

}

return 0;

}




The data for YearOneICT.txt is as follows:

Alan Bob 13176 3.65

Brad Chance 11198 1.71

Chelsea Donald 39528 2.14

David Edwards 22469 3.88

Elenor Franks 44938 3.46

Fred Guess 11246 3.50

Gavin Hill 79056 1.20

Helen Indar 69360 3.20

Ian James 44888 2.58

Jenny Kahn 34168 1.83


The program aims to capture the data from the text file and generate an output file with the format:

ClassSummary.txt

Honours List:

David Edwards 22469 3.88

Progressing Normally:

Alan Bob 13176 3.65

Chelsea Donald 39528 2.14 …

Academic Probation:

Brad Chance 11198 1.71 …

Donald W.

There are a lot of complier errors in the code and, in some cases, it's not clear what the intention is. For example, what is "sp[i] = -1;" supposed to do? sp is an array of students objects, so you can't assign an integer to it. I think it's best that you find a tutor to help you fix this together so you can learn how to fix these issues yourself at the same time.
Report

06/22/22

1 Expert Answer

By:

Anita Z. answered • 06/23/22

Tutor
4.9 (100)

Computer Science and C/C++/C# Tutor; ESL/ESOL Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.