My code just works here for speller. I am receiving 4 out of 5 in style. A 5 over 5 will make me pass this pset by crossing 70% threshold. Can you Please spot errors in style?
// Implements a dictionary's functionality
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "dictionary.h"
// Temporary mug for one dict words
char mug[LENGTH + 1] = {'\0'};
unsigned int track_of_dict_words = 0;
int c;
int k = 0;
int j = 0;
int index = 0;
int p = 0;
// Creating nodes
struct node *getNode(void)
{
struct node *pNode = (struct node *)calloc(1, sizeof(struct node));
if (pNode)
{
pNode -> is_word = false;
for(int i = 0; i < 27; i++)
{
pNode -> children[i] = NULL;
}
}
return pNode;
}
// Returns true if word is in dictionary else false
bool check(const char *word)
{
if (root == NULL)
{
return 0;
}
struct node *curr = root;
while (*word)
{
curr = curr -> children[tolower(*word) - 'a'];
if (curr == NULL)
{
return 0;
}
word++;
}
return curr -> is_word;
}
// Inserting values in dictionary in the memory
void insert(const char *key)
{
// Determining the length of the current word
int length = 0;
index = 0;
for(int i = 0; i < LENGTH; i++)
{
if (key[i] == '\0')
{
break;
}
++length;
}
struct node *pCrawl = root;
while (*key)
{
if ((pCrawl -> children[tolower(*key) - 'a']) == NULL)
{
pCrawl -> children[tolower(*key) - 'a'] = getNode();
}
pCrawl = pCrawl -> children[tolower(*key) - 'a'];
key++;
}
pCrawl -> is_word = true;
}
// Loads dictionary returning true if successful
bool load(const char *dictionary)
{
root = getNode();
// Opening dictionary file
FILE *inptr = fopen(dictionary, "r");
if (inptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not open %s.\n", dictionary);
return 3;
}
j = 0;
for (c = fgetc(inptr); (c != EOF); (c = fgetc(inptr)))
{
if ((c == '\n') || (c == EOF))
{
++track_of_dict_words;
mug[j] = '\0';
// Inserting into Trie
insert(mug);
j = 0;
}
if (isalpha(c))
{
mug[j] = c;
++j;
}
}
if (c == EOF)
{
printf("\nLoad Successful.");
return true;
}
else
{
return false;
}
}
// Returns number of words in dictionary if loaded else 0 if not yet loaded
unsigned int size(void)
{
return track_of_dict_words;
}
// Implements unload functionality
bool flush(struct node *voot)
{
if (voot == NULL)
{
return true;
}
for (int i = 0; i < 27; i++)
{
flush(voot -> children[i]);
}
voot = NULL;
free(voot);
return true;
}
// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
flush(root);
//free(root);
return true;
}