I'm missing something in the following code, which is providing a counter that is +1 from correct count when I enter a pre-provided "dictionary" of 143091 entries, but which enters the correct count if I enter a simple, self written "dictionary" of 10 entries. Am I missing something related to EOF or something of that sort?
The calling code is:
Code:
word = malloc(LENGTH);
while(fgets(word,LENGTH,fp))
{
len= strlen (word);
if (len>0 && word[len-1]=='\n') word[--len]= '\0';
insert (&trie, word);
And the insert() function is as follows, where d_cnt is the # of entries:
Code:
void insert(trie_t *pTrie, char key[])
{
//declarations
int level;
int length = strlen(key);
int index;
trie_node_t *pCrawl;
ptrTrie = pTrie;
pCrawl = pTrie->root;
for( level = 0; level < length; level++ )
{
if(CHAR_TO_INDEX(key[level])>=0)
{
index = CHAR_TO_INDEX(key[level]);
}
if(CHAR_TO_INDEX(key[level])<0)
{
index=26;
}
if( !pCrawl->children[index] )
{
pCrawl->children[index] = getNode();//ADDS ANOTHER LEVEL OF NODES
}
pCrawl = pCrawl->children[index];
}
// mark last node as leaf
pCrawl->value = pTrie->dSize;
dSize++;
}
Thanks for your attention.
richard