Hey eveyone. A file, named “grades.txt”, contains student grades for a course in the followingformat separated by spaces: (an example file follows)
First name Last name Midterm Final
Ali Caliskan 60 40
Veli Dalgaci 80 10
Turkan Sevimli 90 50
Ali Yilmaz 30 70
Ahmet Koc 50 50
Write a program which calculates the overall grades of the students and writes them to two separate files: “passed.txt” and “failed.txt”. The midterm is 40 percent of the grade, and the final is 60%. The passing grade is 50. Example output files follow:
First name Last name Midterm Final Overall
passed.txt:
Turkan Sevimli 90 50 66
Ali Yilmaz 30 70 54
Ahmet Koc 50 50 50
failed.txt:
Ali Caliskan 60 40 48
Veli Dalgaci 80 10 38
I can read "grades.txt", but i can not separate numbers.. This is my code;
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i=0;
char* string[100];
char line[100];
char junk[100];
FILE *file = fopen("grades.txt", "r");
if(!file) {
printf("Could not open file. Exiting application. Bye");
return 1;
}
while(!feof(file)) {
fscanf(file,"%[^ \n\t\r]s",line); //Get text
printf("%s\n", line);
fscanf(file,"%[ \n\t\r]s",junk); //Remove any 'white space' characters
}
fclose(file);
}
I separated (Turkan) (Sevimli) (90) (50), but how can i elect numbers and add them?
if a student who has higher grade than 50, program should send it to passed.txt, else failed.txt.