What I am doing -
I am trying to read a file that contains information about processes and create 3 different arrays. One for array name, second for arrival time and third for process time and compute it afterwards. The number of processes are not fixed but for testing purposes I am keeping it to 4 processes.
The first printf line outputs what I desire. The file contents in the form of array.
void readFile() {
int i = 0;
char printLine[10];
char *processName[4];
char *arrivalTime[4];
char *processTime[4];
FILE *processFile = fopen("processes.txt", "r");
while(!feof(processFile)){
fgets(printLine, 10, processFile); // get the line
processName[i] = strtok(printLine, " ");
arrivalTime[i] = strtok(NULL, " ");
processTime[i] = strtok(NULL, "");
printf("%s %s %s\n", processName[i], arrivalTime[i], processTime[i]);
i++;
}
printf("----\n%s %s %s\n", processName[0], arrivalTime[0], processTime[0]);
}
Error - The error(sort of) is that the output of 2nd print line gives me the last process information even though I am printing the 1st element(1st process) information. So, instead of printing 1st element it is printing the last.
processes.txt file looks like this
P1 0 3
P2 1 6
P3 4 4
P4 6 2
P.S. The format of this file will be fixed so no issue there.
I am a real real novice in this. Please excuse my silliness.
EDIT - my output