#include #include #include #include int string_search(char* data, char* target) { } unsigned long ms_diff(struct timeval a, struct timeval b) { unsigned long msa = (a.tv_sec * 1000) + (a.tv_usec / 1000); unsigned long msb = (b.tv_sec * 1000) + (b.tv_usec / 1000); return msb - msa; } int main(int argc, char** argv) { FILE* file; unsigned int length; char* data; char target[256]; int found; struct timeval a, b; /* get start time */ gettimeofday(&a, NULL); /* open the file */ if (argc < 2) { printf("Please pass an input file.\n"); return 0; } file = fopen(argv[1], "r"); if (!file) { printf("Could not open %s for reading.\n", argv[1]); return 0; } /* find the length of the file */ fseek(file, 0L, SEEK_END); length = ftell(file); fseek(file, 0L, SEEK_SET); /* read the file into memory */ data = malloc(length * sizeof(char) + 1); memset(data, 0, length); fread(data, sizeof(char), length, file); gettimeofday(&b, NULL); unsigned long read = ms_diff(a, b); printf("Reading took %lu ms.\n", read); /* ask what should be searched for */ printf("Enter search term: "); scanf("%s", target); gettimeofday(&a, NULL); /* now do the searching */ found = string_search(data, target); gettimeofday(&b, NULL); unsigned long search = ms_diff(a, b); printf("Searching took %lu ms.\n", search); if (found) { printf("Found it!\n"); } else { printf("Not found...\n"); } return 0; }