I am working on pset5 load but it doesn't compile. Could you have a look at my code?
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char* dictionary)
{
FILE* dic = fopen(dictionary, "r");
typedef struct node
{
bool is_word;
struct node* children[27];
}
node;
node* root;
int index;
int prev_index;
int c = fgetc(dic);
//check all the characters until end of the file
while(c != EOF)
{
//check whether the first character of a word is letter or apostrophe
if(c == !'\'')
{
index = tolower(c) - 'a';
prev_index = tolower(c) - 'a';
if(root == NULL)
{
node* root = calloc(1, sizeof(node));
root -> children[index] = c;
}
}
else
{
index = 27;
prev_index = 27;
if(root == NULL)
{
root -> children[index] = c;
}
}
//iterate through all of the rest letters/apostrophes in the word
while(c != '\0')
{
int c = fgetc(dic);
node* children = calloc(1, sizeof(node));
if(c == !'\'')
{
index = tolower(c) - 'a';
if(children[index] == NULL)
{
children[prev_index] -> children[index] = c;
prev_index = index;
index++;
}
}
else
{
index = 27;
if(children[index] == NULL)
{
prev_index = tolower(c - 1) - 'a';
children[prev_index] -> children[index] = c;
prev_index = 27;
index++;
}
}
}
is_word = true;
prev_index = 0;
index = 0;
c = fgetc(dic);
}
return true;
}
When I try to make it compile it gives four major errors:
dictionary.c:59:41: error: incompatible integer to pointer conversion assigning to 'struct node *' from 'int' [-Werror,-Wint-conversion] root -> children[index] = c;
dictionary.c:83:36: error: invalid operands to binary expression ('node' (aka 'struct node') and 'void *') if(children[index] == NULL)
dictionary.c:97:42: error: member reference type 'node' (aka 'struct node') is not a pointer; maybe you meant to use '.'? children[prev_index] -> children[index] = c;
dictionary.c:104:9: error: use of undeclared identifier 'is_word' is_word = true; (I have declared it at the beginning when I declared struct, didn't I?)
What are the reasons behind the errors? Did I misunderstand how to use pointers? In what way?
Thank you in advance for your help!