1

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!

4
  • did you watch the short on global variables youtube.com/watch?v=F5feTW3CAZs? – kzidane Nov 8 '15 at 14:47
  • Ok, should I define my pointers in the top of dictionary.c, before all sub functions or rather at the top of dictionary.h? – CharlesD89 Nov 8 '15 at 15:49
  • do you want your global pointers to be accessible in other source files (e.g., speller.c)? – kzidane Nov 8 '15 at 15:55
  • Ok i see, No, so I just need to declare them in dictionary.c in the top. Now I must resolve main code of CHECK cuz it appears my CURRENT pointer is not well declared for the way I want use it. Thx for your help. – CharlesD89 Nov 8 '15 at 16:05
0

The problem is that you set root to NULL.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .