Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Function to check if a word is in the dictionary. Can be
- * easily modded to take in a dictionary. Will loop through
- * the dictionary until it finds a word or until the given word
- * is smaller than current position - meaning it wasn't found.
- * @param word a char array to check if in dictionary.
- * @return 1 or 0 if found or not respectively.
- */
- int isInDictionary( char *word )
- {
- //word to be compared, must be made lowercase
- //but we don't want to modify the word itself.
- char lowercaseWord[ strlen( word ) + 1 ];
- for ( int i = 0; i < strlen( word ); i++ ) {
- lowercaseWord[i] = tolower( word[i] );
- }
- lowercaseWord[ strlen( word ) ] = '\0';
- for ( int i = 0; i < dictionarySize; i++ ) {
- if ( strcmp( lowercaseWord, dictionary[i] ) == 0 ) {
- return 1;
- } else if ( strcmp( lowercaseWord, dictionary[i] ) < 0 ) {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement