My questions is how can I make this program more efficient. I have ran out of ideas of what to do. This program takes way too long to execute. I just starting coding in C 3 months ago so I don't know what else to do.
This code is part of a bigger program, and is the bottle neck. I have to call function meaningful about 2000 times, which checks if the argument passed to it is actually a word. The function goes through a dictionary to see if str is actually a word.
I would appreciate any help I can get on this to make it faster.
Code:#include <stdio.h> #include <string.h> main() { void meaningful(char *); char hello[20] = {'b','r','e','a','d'}; int i, ticktok = 0; clock(NULL); for(i = 0; i < 2000; i++) meaningful(hello); ticktok = clock(NULL); printf("Clocks: %i\n", ticktok); } void meaningful(char *str) { char temp[20]; int i = 0, match=0, t; FILE *fp; fp = fopen("/usr/share/lib/dict/words", "r"); while(fscanf(fp, "%s", temp) != EOF){ if(isupper(temp[i])) temp[i] = tolower(temp[i]); if(temp[0] != str[0]) continue; if(temp[1] != str[1]) continue; if(temp[2] != str[2]) continue; t = strcmp(temp,str); if(t == 0){ //printf("****match found*****\n"); //printf("%s\n",temp); break; } if(t > 0) break; } fclose(fp); }



LinkBack URL
About LinkBacks



I'm sure you can find detailed information on AVL trees all over the web, so I won't post the code here.