# Problem with Hash Table Linear Probing

• 10-23-2002
kirby1024
Problem with Hash Table Linear Probing
The problem here is that for some reason, about 23rd time through the main loop in readList(), it decides to read to NULL, and I have no idea why it is happening.

The code is attached (as well as mostly documented), it compiles fine in lcc-win. The test file used can be found at:

http://www.csse.monash.edu.au/course...rac06/dict.txt
• 10-23-2002
dat
I know this isn't an answer but why are you using C for text manipulations? Why not use Perl? It's really easy for the task you're trying to conquer.
• 10-23-2002
kirby1024
Because as the hyperlink probably indicates, this is a university course, and uses C. Also, I don't know any Perl. I'm only first year Uni student!
• 10-23-2002
kirby1024
Thanks for the debugs, but the problem is still persisting. 23rd loop through, the test printf gets to #, and windows informs me that the program is attempting to write to NULL.

Which, I guess, means that the in-code comment in the code is probably at the wrong place. The error, 23rd time around, somewhere around here:

Code:

```//Is a code fragment. Full program attached to first post.         printf("#");        //test printf         value = hash(readin);         count = 0;         while(htable[value] != NULL)         {                 value = (value + 1) % TABLESIZE;                 count++;                                                                if(count >= TABLESIZE - 1)                                {                         printf("Table is Full\n");                         return;                 }                 printf("\$");        //test printf         }         htable[value] = malloc(sizeof(strlen(readin))+1);         if(htable[value] == NULL)         {                 fprintf(stderr, "Out of Memory");                        iexit(htable, 0);         }         printf("%%");        //test printf```
If the Hash table were full (and my code to check that it's full is working), it should just exit back to main, print out that the table is full, then go on. It's not done that. I even know that the linear probing works properly as the sequence of the test printfs is as follows:
!@#%^#%^#%^#%^#%^#%^#%^#\$%^#%^#%^#%^#%^#%^#%^#%^#%^#%^#%^#%^#%^#%^#%^#

The \$ sign there shows that it's gone through the stepping at least once.

This is really frustrating!
• 10-23-2002
kirby1024
OK, yet another problem found. I decided to see if it was hashing properly, so I inserted a call to list(). I found out that for some reason, any words 8 characters or more are abbreviated to 8 characters, with a symbol placed at position 9 (in DOS, it's the smily symbol, ASCII Value 2).

That shouldn't be happening...
• 10-23-2002
kirby1024
Thanks - It looks like that's solved the problem.

Gracias!