geneviedube

Untitled

Sep 3rd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. /**
  2.  * Returns true if word is in dictionary else false. Word not in disctionnary = misspelled
  3.  */
  4. bool check(const char *word)
  5. {
  6.      // sign for apostrophe is backshash '\''
  7.     char c = 0;
  8.  
  9.     // check if dictionary is loaded
  10.     if (root == NULL)
  11.     {
  12.         printf("root is NULL");
  13.         return false;
  14.     }
  15.  
  16.           //if one letter is not good, than the word is not in the dictionnary but it s a word => result is misspelled
  17.  
  18.     // iterate every letters of the word until end of file making sur that max lenght is 27 // ide tells me to replace "\0" by strncmp
  19.     for (int i = 0; i < word[LENGTH + 1]; i++)  //(int letter_position = 0; word[letter] != EOF; letter++)
  20.     {
  21.         //allowed only alphabetical characters and apostrophes
  22.         if (isalpha(c)) //letter position > 0 means a word more than 1 letter
  23.         {
  24.             //if letter is capital, make it lower to make sure no sensitive case to be count misspelling by error because of capital
  25.             if (isupper(c))
  26.             {
  27.                 letter_position = (c - 65);
  28.             }
  29.  
  30.             if (islower(c))
  31.             {
  32.                 letter_position = (c - 97);
  33.             }
  34.  
  35.             if (c == '\'')
  36.             {
  37.                 letter_position = 26;
  38.             }
  39.  
  40.             //word[letter_position] = c //match the caracter of the text to the pointer in dictionary
  41.             //letter_position++   // move to the next letter position// find the position of the letter
  42.  
  43.             // go to next letter and check if it does exist
  44.             if (temp_pointer->children[letter_position] != NULL)
  45.             {
  46.                 //move to the next nde
  47.                 temp_pointer = temp_pointer->children[letter_position];
  48.             }
  49.  
  50.         }
  51.         //Only return true if the pointer goes until the end of the word
  52.         if (temp_pointer->is_word)
  53.         return true;
  54.  
  55.     }
  56.     return false;
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment