Can anyone tell me why this function is not being executed properly? It is jumping straight to the end and printing the last line:
"0 pages faults"
when there should definitely be some activity. I'm not sure if the function is picking up the values and getting passed properly when I call it in the main function.
File to be read:
8 4 12
4
3
4
6
1
6
4
5
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <time.h>void runningMessage(int, int, int);void fifo();int flag = 0, var, currFrame = 0, numFault, currRequest,minRequest,maxRequest ,request;int numPages, numFrames, numRequest, fc =0, go =0, c =0;void runningMessage(int pg, int frame, int msg){ if(msg == 1) { printf("Page %d already in Frame %d\n",pg, frame); } if(msg == 2) { printf("Page %d loaded into Frame %d\n",pg, frame); } if(msg == 3) { printf("Page %d unloaded from Fram %d\n",pg, frame); }}int main(int argc, char *argv[]){ FILE *fp; fp = fopen(argv[1], "r"); int x =0; fscanf(fp, "%d %d %d", &numPages, &numFrames, &numRequest); int pgAccess[numRequest],pgArray[numPages], pgRequest[numRequest]; while(!feof(fp)) { fscanf(fp, "%d", &pgAccess[x]); x++; } fclose(fp); printf("Algorithm: %s\n\n", argv[2]); var = numRequest; if(strcmp(argv[2] ,"FIFO") == 0) { fifo(&pgArray, &pgAccess, numPages, numFrames, numRequest, var); }}void fifo(int *pgArray, int *pgAccess, int numPages, int numFrames, int numRequest, int var){ int i, x, y; for(i = 0; i < numFrames; i++) { pgArray[i] = -1; } while(x < numRequest) { flag =0; var = pgAccess[x]; for(i = 0; i < numFrames; i++) { if(var == pgArray[i]) { flag = 1; x++; runningMessage(pgArray[i], i, 1); break; } } if(flag == 0) { if(currFrame < numFrames) { pgArray[currFrame] = pgAccess[x]; runningMessage(pgAccess[x], currFrame, 2); currFrame++; x++; numFault++; } else if( y < numFrames) { runningMessage(pgArray[y], y, 3); pgArray[y] = pgAccess[x]; runningMessage(pgAccess[x], y, 2); x++; y++; numFault++; } else { y =0; } } } printf(" %d Page Faults\n\n", numFault);}