int C_SIZE = atoi(argv[1]); // Size of Cache passed by user char pageCache[100]; // Cache that holds the input from test file
struct queue *q; // Main page queue
q = queue_create();
int totalFaults = 0; // keeps track of the total page faults
int totalHits = 0; // keeps track of the total page hits int totalPages = 0; // keeps track of the total number of pages requests
while (fgets(pageCache, 100, stdin)){
int page_num = atoi(pageCache); //Stores number read from file as int totalPages++;
if (queue_find(q, page_num) != NULL) { // Checks to see if the current page is in the
queue already fprintf(stderr, "Hit: %d\n", page_num); totalHits++; } else { // Page is not in the queue printf("Miss: %d\n", page_num); totalFaults++; if (queue_length(q) >= C_SIZE) { // Checks to see if the queue is already at max capacity or not dequeue(q); enqueue(q, page_num); fprintf(stderr, "Old page removed, %d added\n", page_num); } else { enqueue(q, page_num); fprintf(stderr, "%d added\n", page_num); } } }