'Writing code in c utilizing imported data from a tsv file
Question Prompt1
I am very new to C and I didn't really understand this chapter in my text book. This is the final version of my code that I have written, although, I have been at this for 3 hours straight.(p.s. some of the code is intentially surrounded by slashes because of testing purposes.)
#include <stdio.h>
int main(void) {
FILE* StudentInfo = NULL;
FILE* Report = NULL;
int x = 0;
int Reader = 1;
const int STUDENT_LINE_INFO = 50;
char studentGrades[STUDENT_LINE_INFO];
char firstName[25];
char lastName[25];
int score1;
int score2;
int score3;
int studentAvg;
/*int midterm1;
int midterm2;
int final;*/
StudentInfo = fopen("StudentInfo.tsv", "r");
while(fgets(studentGrades, STUDENT_LINE_INFO, StudentInfo)) {
printf("%s", studentGrades);
sscanf(studentGrades, "%25s %25s %d %d %d", lastName, firstName, &score1, &score2, &score3);
studentAvg = ((score1 + score2 + score3) / 3);
}
printf("%d", studentAvg);
/* Report = fopen("report.txt", "w");
fprintf("%s", studentGrades);
fprintf("Averages: midterm1 %d, midterm2 %d, final %d", midterm1, midterm2, final);
if (x >= 90) {
fprintf(Report,"A");
}
else if ((x < 90) || (x >= 80)) {
fprintf(Report, "B");
}
else if ((x < 80) || (x >= 70)) {
fprintf(Report, "C");
}
else if ((x < 70) || (x >= 60)) {
fprintf(Report, "D");
}
else {
fprintf(Report, "F");
}
fclose(Report); */
return 0;
}
I need some help please. I know this code is uncomplete but I dont know if it is even remotely close to what I need to be doing. Is this even the right approach?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
