I have an assignment to create a CPU scheduler by reading in process information from an input file like this:
q 1 tq 4 p1 30 p2 10 p3 24 p4 20 p5 17 p6 4 p7 7 p8 11 p9 8 p10 9 p11 5 p12 6 p13 3 p14 2 p15 1
q 2 tq 5 p1 1 p2 2 p3 2 p4 9 p5 8 p6 5 p7 12 p8 11 p9 15 p10 1 p11 4 p12 8 p13 22 p14 21 p15 30
q 3 tq 30 p1 30 p2 10 p3 24 p4 20 p5 17 p6 4 p7 7 p8 11 p9 8 p10 9 p11 5 p12 6 p13 3 p14 2 p15 1
where q x
is "ready queue x", tq y
is time quantum y and the rest in the line is in the format pv w
, where pv
is p1, p2, p3,..., p15 and are the process names and w
is the CPU burst time. each queue are to be read from the same input file and stored in separate arrays of struct
that contains the time quantum, process name and the CPU burst time:
struct process{
char name[4];
int cputime;
int timequantum;
};
How would I accomplish this? I should mention that I have only just started with this C course and have never been taught how to read input files in C.