hey guys, any suggestions on how to check a strings against a dictionary. To check the whole string I got, but lets say that the string has five characters (T O A D N) and is ended with a '\0', only the first four make a word. The code that I'm in the process of figuring out is below. It returns the word fine, as long as it is a value of the total string. Also, there are a maximum of characters in each string.
the dictionary is stored in a 2D array. any suggestions?Code:void matchWord(char word1[], char word2[], char dictionary[][MAX_LENGTH + 1]) { int i; int j; if ( word1[2] == '\0') { for ( i=0; i<7000; i++) { if ( strcmp( word1, dictionary[i]) == 0 ) { cout << endl << word1 << endl; break; // quit looking } } } else if( word1[3] == '\0') { for ( i=0; i<7000; i++) { if ( strcmp( word1, dictionary[i]) == 0 ) { cout << endl << word1 << endl; break; // quit looking } } } else if ( word1[4] == '\0') { for ( i=0; i<7000; i++) { if ( strcmp( word1, dictionary[i]) == 0 ) { cout << endl << word1 << endl; break; // quit looking } } } else if ( word1[5] == '\0') { for ( i=0; i<7000; i++) { if ( strcmp( word1, dictionary[i]) == 0 ) { cout << endl << word1 << endl; break; // quit looking } word1[4] == '\0'; if ( strcmp( word1, dictionary[i]) == 0 ) { cout << endl << word1 << endl; break; // quit looking } } } }
axon



LinkBack URL
About LinkBacks


