0

well i have a problem with speller problem set 5 code. For some reason check50 returns everything wrong but when i debug it seems fine. I don't really know what the problem with my code is. This is my code.

// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
// TODO
//open dictionary file
FILE *diction = fopen(dictionary ,"r");
// if value is not NULL return 1 to show it is not successfull
 if(diction == NULL)
{
    return false;
}

//Read strings from one file at a time
char *wordie = malloc((LENGTH + 1) * sizeof(char));
while(fscanf(diction, "%s", wordie) != EOF)
 {

 //create a new node
  node *n = malloc(sizeof(node));
   if(n == NULL)
   {
        return false;
   }
   strcpy(n->word , wordie);

 // Hash word to obtain hash value
int hashed = hash(n->word);

//insert node into the hash table
n->next = table[hashed];
table[hashed] = n;

//count the no of nodes in hash table
node *ptr = NULL;
ptr = table[hashed];
while(ptr != NULL)
{
      word_count++;
      ptr = ptr->next;

}

ptr = table[hashed];
while(ptr != NULL)
{
     free(ptr);
     ptr = ptr->next;
  }
 }  


free(wordie);
          fclose(diction);

return true;

}
3
  • "debug" is one thing. Running the code is another. Have you run the program and gotten the expected result? It looks like this program frees the nodes in load. When check runs, the hash table is essentially empty and everything will be marked as misspelled. Commented Feb 23 at 23:00
  • then how do i free the node.pls help me
    – dhan8293
    Commented Feb 24 at 8:38
  • implemented in the unload function Commented Feb 24 at 10:39

0

You must log in to answer this question.

Browse other questions tagged .