Advertisement
Shanix

Untitled

Mar 15th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /**
  2. * Function to check if a word is in the dictionary. Can be
  3. * easily modded to take in a dictionary. Will loop through
  4. * the dictionary until it finds a word or until the given word
  5. * is smaller than current position - meaning it wasn't found.
  6. * @param word a char array to check if in dictionary.
  7. * @return 1 or 0 if found or not respectively.
  8. */
  9. int isInDictionary( char *word )
  10. {
  11. //word to be compared, must be made lowercase
  12. //but we don't want to modify the word itself.
  13. char lowercaseWord[ strlen( word ) + 1 ];
  14. for ( int i = 0; i < strlen( word ); i++ ) {
  15. lowercaseWord[i] = tolower( word[i] );
  16. }
  17.  
  18. lowercaseWord[ strlen( word ) ] = '\0';
  19. for ( int i = 0; i < dictionarySize; i++ ) {
  20. if ( strcmp( lowercaseWord, dictionary[i] ) == 0 ) {
  21. return 1;
  22. } else if ( strcmp( lowercaseWord, dictionary[i] ) < 0 ) {
  23. break;
  24. }
  25. }
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement