Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- student *studentsArray;
- char *inputFile = malloc(100);
- char *outputFile = malloc(100);
- char line[100];
- FILE *dataFile;
- int studentCount = 0;
- int lineCount = 0;
- int i, j = 0;
- fputs("Please enter file to open ", stdout);
- fflush(stdout);
- if(fgets(inputFile, sizeof inputFile, stdin) != NULL)
- {
- printf(inputFile);
- char *newline = strchr(inputFile, '\n');
- if( newline != NULL)
- {
- *newline = '\0';
- }
- }
- dataFile = fopen(inputFile, "r");
- if(dataFile == NULL)
- {
- fprintf(stderr, "Unable to read text file");
- return 1;
- }
- while(fgets(line, 100, dataFile) != NULL)
- {
- switch(lineCount)
- {
- case 0:
- strcpy(studentsArray[studentCount].studentId, line);
- lineCount++;
- break;
- case 1:
- strcpy(studentsArray[studentCount].studentName, line);
- lineCount++;
- break;
- case 2:
- studentsArray[studentCount].studentGrades[j] = atof(strtok(line, " "));
- while(studentsArray[studentCount].studentGrades[j] != NULL)
- {
- studentsArray[studentCount].studentGrades[j] = atof(strtok(NULL, " "));
- j++;
- }
- lineCount = 0;
- j = 0;
- studentCount++;
- break;
- }
- }
- fclose(dataFile);
- // Get all the calculated final grades for each student
- studentsArray = calculateFinalGrades(studentsArray);
- fputs("Please enter file to output to ", stdout);
- fflush(stdout);
- if(fgets(outputFile, sizeof(outputFile), stdin) != NULL)
- {
- char *newline = strchr(outputFile, '\n');
- if( newline != NULL)
- {
- *newline = '\0';
- }
- }
- printStudentGrades(studentsArray, outputFile);
- return 0;
- }
Add Comment
Please, Sign In to add comment