I am trying to assign output grade off from input file, as well as output average, minimum and maximum grades Each assignment is.
For example, an input file for a class with 4 students and 3 assignments can look like:
8.5, 10.5, 90.5 49.5, 99, 97 88, 88, 100 88.5, 99, 0
should be more input
Student grade from input file: 8.5, 10.5, 90.5 49.5, 99.0, 97.0 88.0, 88.0, 100.0 88.5, 99.0, 0.0 Assignment # 1 Stats Average = 58.6 minutes = 8.5 Max = 88.5 Assignments # 2 Figures Average = 74.1 Minimum = 10.5 Max = 99.0 Assignment # 3 Statistics Average = 71.9 minutes = 0.0 Max = 100.0
So far, I have a first part I'm stuck where I have to output the contents of the file. This is what I have done so far, any help or work on this would be greatly appreciated.
int main (int argc, char * argv []) {FILE * input_file; Int line_number = 0; Char * next_field; Four lines [MAX_STUDENTS + 1]; Input_file = fopen (argv [1], "r"); // Use grads from the input file while (1) {fgets (line, MAX_STUDENTS, input_file); If break (FIF (input_file)); Next_field = strtok (row, "\ n"); While (next_field! = NULL) {printf ("================================== / n"); Printf ("Student grade / n from input file"); Printf ("================================== / n"); Printf ("% s,", next_field); Next_field = strtok (NULL, "\ n"); }}
You can identify and output like this:
#include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; #include & lt; String.h & gt; # Include & lt; Errno.h & gt; # Include & lt; Ctype.h & gt; # Defined MAX_LINE_LEN 1024 int main (int argc, char ** argv) {int line_number = 0; File * input_file; Four line [MAX_LINE_LEN + 1]; Char * next_field; Char * end_field; If (1 == argc) {fprintf (stderr, "Usage:% s ; \ n", argv [0]); Exit (1); } If (navel == (input_file = FOPAN (RGR [1], "R")) {mirror (RGR [1]); Exit (1); } Fprintf (stdout, "Student grade from input file: \ n"); While (fgets (line, size (line), input_file)) {int first = 1; ++ line_number; (Next_field = strtok (line, ", \ n"); NULL! = Next_field; next_field = strtok (NULL, ", \ n")) {errno = 0; Double grade = strotode (next_field, and end_field); If (anonymous) and_field == next_field || * end_field) {fprintf (stderr, "warning: malicious input '% s'? Skip! \ N", next_field); to continue; } Fprintf (stdout, "% s% .1lf", (first? "": ","), Grade); First = 0; // TODO: store grade (or minimum running minimum, maximum, average) in a structure that later stores assignment data for processing and printing} if (! First) fprintf (stdout, "\ n") ; } Return 0; }
You will need to store any kind of structures about each assignment so that you can print assignment statistics after reading all the inputs.
Note that I call "\ n" with "code \ n", \ n "instead of \" I believe that the comma actually has significant delimiters in your input less than Less, this is especially true for .csv files, which is a common format for processing data.
Note, both of our views will do some worrisome things on different types of input. For example, your tokening does not work well If a line looks like "7.0.8.0 9.0,10.0 \ n"
, which is normal in .cc files, your program will only process 7.0
and the remaining line will be processed Your program will also ignore that there will be no object on the input such as "7.0, Hiitre 8.0, 9.0 \ n"
. Then, the probability of your program is "7.0 8.0 9.0, 10.0 \ n "
because it is " 7.0, 8.0, 9.0, 10.0 \ n "
even if some former string was missing comma. Is it bad or not? The answer depends on your input file format and how tough you want it to be on its structure. For the pre-string, my tokenizan approach, 7.0
to ','
, '\ n'
or '\ 0'
is in the original input, but allows a white space before a number starts, which is some strange asymmetric treatment of white space. It will also process "7.0 ,,, 0.0.0 \ n"
code without seeing "missing" fields on the line.
So, you need to know how to pick up the pickup that you want to deal with in your program by mistake.
No comments:
Post a Comment