0

I was woring on pset5 and I have been working with a small dictionary with just 71 words, when I check my own text files with 8 words all is working well except that it gives out number of words to be 72 instead of 71...any help would be appreciated

unsigned int size(void)
{


    int counter = 0;
    for(int i = 0; i < HASHTABLESIZE; i++)
    {
        if(hashtable[i] != NULL)
        {
            for(node* ptr = hashtable[i]; ptr != NULL; ptr = ptr->next)
            {
                counter++;
            }
        }
    }
    // if dictionary was not loaded that means there were no words.
    if(counter == 0)
    {
       return 0;
    }
    else
    {
        return counter;
    }    
}

deleted some of the code deu to academic honesty, I solved my problem

2
  • Not enough code. Need to see the entire load function, the hash function and the data structure.
    – Cliff B
    Aug 18 '16 at 9:46
  • Done have added them all Aug 18 '16 at 10:25
1

Classic error. When processing the dictionary file, your code will read from the input file, process it, and then check for EOF. This is causing an extra word being added somewhere when the end of file is processed. I'm not sure if a duplicate word is being added or a node with a blank word is being added. Maybe you can test with your 71 word dictionary.

I'm guessing that this is also contributing to your unload problem in the other question, which I haven't tested yet. Please update that question with an explanation of the problem, it's symptoms and any errors produced so that it can be duplicated.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • yes just checked with gdb an extra node is been made at the end, how do I solve this problem? and yes I have elaborated my problem in the other question too Aug 18 '16 at 12:29
  • deleted some of the code deu to academic honesty reasons Aug 18 '16 at 14:52
0

You should probably check your small dictionary file. Chances are that you're detecting a new word when you see a newline character (\n). Try counting the number of lines after the last word in your dictionary file. There should only be one.

You must log in to answer this question.

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