Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns true if word is in dictionary else false. Word not in disctionnary = misspelled
- */
- bool check(const char *word)
- {
- // sign for apostrophe is backshash '\''
- char c = 0;
- // check if dictionary is loaded
- if (root == NULL)
- {
- printf("root is NULL");
- return false;
- }
- //if one letter is not good, than the word is not in the dictionnary but it s a word => result is misspelled
- // 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
- for (int i = 0; i < word[LENGTH + 1]; i++) //(int letter_position = 0; word[letter] != EOF; letter++)
- {
- //allowed only alphabetical characters and apostrophes
- if (isalpha(c)) //letter position > 0 means a word more than 1 letter
- {
- //if letter is capital, make it lower to make sure no sensitive case to be count misspelling by error because of capital
- if (isupper(c))
- {
- letter_position = (c - 65);
- }
- if (islower(c))
- {
- letter_position = (c - 97);
- }
- if (c == '\'')
- {
- letter_position = 26;
- }
- //word[letter_position] = c //match the caracter of the text to the pointer in dictionary
- //letter_position++ // move to the next letter position// find the position of the letter
- // go to next letter and check if it does exist
- if (temp_pointer->children[letter_position] != NULL)
- {
- //move to the next nde
- temp_pointer = temp_pointer->children[letter_position];
- }
- }
- //Only return true if the pointer goes until the end of the word
- if (temp_pointer->is_word)
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment