/**************************** * Project 1 * Output Test File 4 * 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 another file 1000 //times, then waits 5 seconds, // keeping track of the time //it takes each time. Each write //backs up and writes the file again. //Do this 100 //times with a 5 second break in //between each time. int main(int argc, char* argv[]) { //variable declarations char* inputfilename; char* outputfilename; float timeStore[100]; char inputStore[100000]; FILE *input, *output; struct stat fileStats; int i = 0, j = 0; //if command line does not contain filename, exit if (argc < 3) { 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]; outputfilename = argv[2]; if ((output = fopen(outputfilename, "r")) != NULL) { printf("Output file already exists, please enter a new output file.\n"); exit(0); } if ((output = fopen(outputfilename, "w+")) == NULL) { printf("The output file could not be opened to write."); exit(0); } 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] = fileToFile(inputStore, output, 1000, i, 1); fprintf(stderr, "Overall Time Delta: %.1f ticks\n\n", timeStore[j]); rewind(output); sleep(5); } } else { printf("File too large for this program, please use something under 100k."); } fclose(output); fclose(input); printf("Final timing list:\n"); for (j = 0; j < 100; j++) { fprintf(stderr, "%f\n", timeStore[j]); } } return 0; }