I'm now working on the implementation of CHECK subfunction. I think I'm on the good way, but my major problem at this moment is to link CHECK with the loaded dictionary. I'm pretty sure I can't access to LOAD's pointers once LOAD is executed. There, the initialising part of my LOAD function :
// open dictionary file
FILE* inptr = fopen(dictionary, "r");
if (inptr == NULL)
{
....
}
// define structure of the nodes
typedef struct node
{
bool is_word;
struct node* children[NB_NODES];
} node;
// keep track of the first node
node* root = NULL;
// initialize value
int word_counter = 0;
node* current = NULL;
for (int c = fgetc(inptr); c != EOF; c = fgetc(inptr))
{....
I thought my pointers used in LOAD have been globally declared but it doesn't seem. So, how can I resolve that without modifying prototype of CHECK function? Someone could help me with that? Here main body of my check implementation :
bool check(const char* word)
{
// initialize pointers and variables
int index = 0;
node* root = NULL;
node* current = NULL;
current = root;
for (int i = 0, n = strlen(word); i < n; i++)
{
if (isalpha(word[i]))
{
if (i == 0)
{
index = tolower(word[i] - 'a');
current = current->root[index];
}
else
{
index = tolower(word[i]) - 'a';
cucurrent->children[index];
}
}
else if (word[i] == '\'' && i > 0)
{
...
}
else if (word[i] == '\0' && i > 0 && i == n-1)
{
...
}
}
...
Thanks for your help!