I am currently writing a basic program scheduler (just started) which we have a text file with format of Process(id) (space) (quantum) (space) (priority).
I am working on the first bit of the program actually reading in the text file and am trying to assigned the process ids, quantum and priority. ( I think this is the right way to start)
this is what i have so far
#include <stdio.h>
int main ( int argc, char *argv[] )
{
int i;
char current[14]; /* the string for reading in characters from txt file */
/*assigned now but used in different part of program not written yet*/
int ProcessID;
int Quantum;
int Priority;
// We assume argv[1] is a filename to open
for(i = 1; i < 4; i = i+1) // for loop (starting; while_true; do_this).
{
FILE *file = fopen( argv[i], "r" );
/* fopen returns NULL on failure */
if ( file == NULL )
{
printf( "Could not open file\n" );
}
else
{
/* read one character at a time from file, stopping at EOF, which
indicates the end of the file. Note that the idiom of "assign
to a variable, check the value" used below works because
the assignment statement evaluates to the value assigned. */
while ( ( current[14] = fgetc( file ) ) != EOF )
{
/* Assign 8th letter as the process id*/
if (current[8] >= '0' && current[8] <= '9')
{
Current == ProcessID;
}
/* Assign 10th and 11th characters as the quantum*/
else if (current[10,11] >= '0' && current[10,11] <= '9')
{
current = Quantum;
}
/* Assign the 13th and 14th character as the priority */
else if (current[13,14] >= '0' && current[13,14] <= '20')
{
current = Priority;
}
}
}
fclose( file );
}
}
As my understanding goes, this program is reading in the file name, then looping through each character at a time. Then im trying to assign the 8th character as id, 10th and 11th as quantum and 13th and 14th as the priority.
I just seem to be stuck at this point in time. Any help is greatly appreciated.