/**************************** * Project 1 * Output Test File 2 * Good Student * CS 3113 * Dr. Hougan ****************************/ //Include Files #include #include #include #include #include "out_test.h" /****************************/ //Main function //Takes in a file name, then //writes it to the stdout 1000 //times, keeping track of the time //it takes each time. Do this 100 //times with a 5 second break in //between each time. int main(int argc, char* argv[]) { //variable declarations char* inputfilename; float timeStore[100]; char inputStore[100000]; FILE *input; struct stat fileStats; int i = 0, j = 0; //if command line does not contain filename, exit if (argc < 2) { printf("Too few arguments given.\nCorrect syntax: %s \n", argv[0]); exit(0); } //read in the file given in the command line inputfilename = argv[1]; if ((input = fopen(inputfilename, "r")) == NULL) { printf("Either the file %s does not exist, or there has been a problem opening it. Please try again."); } else { stat(inputfilename, &fileStats); if (fileStats.st_size < 100000) { fprintf(stderr, "File Size: %d\n", fileStats.st_size); while ((inputStore[i] = fgetc(input)) != EOF) { i++; } for (j = 0; j < 100; j++) { fprintf(stderr, "Trial run %d:\n", j+1); timeStore[j] = fileToStdOut(inputStore, 1000, i); fprintf(stderr, "Overall Time Delta: %.1f ticks\n\n", timeStore[j]); sleep(5); } } else { printf("File too large for this program, please use something under 100k."); } printf("Final timing list:\n"); for (j = 0; j < 100; j++) { fprintf(stderr, "%f\n", timeStore[j]); } } return 0; }