When it comes to checking a word, it seems like there is no connection between the nodes.
This where I am not getting the desired return. It's right under the check function.
if(checker -> childern[temp] != NULL){
checker = checker -> childern[temp];
printf("\not Null \n");
}
typedef struct node{
bool is_word;
struct node* childern[27];
}
node;
node* pointer;
int dictionarySize = 0;
bool check(const char* word)
{
node* checker = pointer;
for(int i = 0; i < strlen(word); i++){
if(isalpha(word[i])){
int temp = tolower(word[i]) - 'a';
// printf("Check Letter: %d\n", temp);
if(checker -> childern[temp] != NULL){
checker = checker -> childern[temp];
printf("\not Null \n");
}
else{
// printf("\nSize: %lu\n", strlen(word));
// printf("\ni: %d\n", i);
// printf("\nWe have a null\n");
return false;
}
}
}
return true;
}
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char* dictionary)
{
//Reading the dictionary
FILE* book = fopen(dictionary, "r");
if(book == NULL){
printf("Unable to open the dictionary !");
return false;
}
// Declaring nodes.
node* root = calloc(1, sizeof(node));
pointer = root;
// root -> is_word = false;
//First letter from dictionary
int currentLetter = fgetc(book);
int index;
while(currentLetter != EOF ){
if(currentLetter == '\n'){
pointer -> is_word = true; //THIS NEEDS TO BE FIXED
pointer = root;
dictionarySize ++;
printf("\n");
}
else if(isalpha(currentLetter)){
index = tolower(currentLetter) - 'a';
if(pointer -> childern[index] == NULL){
pointer -> childern[index] = calloc(1, sizeof(node));
pointer = pointer -> childern[index];
// printf("Letter: %c\n", index + 97);
}
else{
pointer = pointer -> childern[index];
// printf("No Null\n");
}
}
currentLetter = fgetc(book);
}
if(!ferror(book)){
fclose(book);
return true;
}
else{
fclose(book);
return false;
}
}