Reading the marks from a file
Nothing remarkable in this file:
#include "calcmarks.h" // local header file provides declarations
int readmarks(FILE *fp)
{
char line[BUFSIZ];
int nmarks = 0;
double thisproj;
double thisexam;
....
// READ A LINE FROM THE FILE, CHECKING FOR END-OF-FILE OR AN ERROR
while( fgets(line, sizeof line, fp) != NULL ) {
// WE'RE ASSUMING THAT WE LINE PROVIDES TWO MARKS
.... // get 2 marks from this line
projmarks[ nmarks ] = thisproj; // update global array
exammarks[ nmarks ] = thisexam;
++nmarks;
if(verbose) { // access global variable
printf("read student %i\n", nmarks);
}
}
return nmarks;
}
|
CITS2002 Systems Programming, Lecture 17, p8, 26th September 2023.
|