Problem with Hash Table Linear Probing

This is a discussion on Problem with Hash Table Linear Probing within the C Programming forums, part of the General Programming Boards category; The problem here is that for some reason, about 23rd time through the main loop in readList(), it decides to ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    19

    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
    Attached Files Attached Files

  2. #2
    dat
    dat is offline
    Registered User
    Join Date
    Nov 2001
    Posts
    28
    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.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    19
    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!

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    19
    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!
    Last edited by kirby1024; 10-23-2002 at 06:36 AM.

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    19
    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...

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    19
    Thanks - It looks like that's solved the problem.

    Gracias!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging Hash Table Implementation
    By aim4sky in forum C Programming
    Replies: 9
    Last Post: 03-14-2008, 06:01 PM
  2. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 06:06 PM
  3. Insert Items in Hash Table Container.
    By joenching in forum C++ Programming
    Replies: 18
    Last Post: 05-02-2005, 02:50 PM
  4. Hash Table Problem
    By Unregistered in forum C Programming
    Replies: 14
    Last Post: 05-21-2002, 05:34 PM
  5. 2D table problem
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 12-10-2001, 03:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21