![]() |
|
#1
|
|||
|
|||
Hash table problem.Hi, I'm sorry to trouble anyone, but I've been writing a C program for a hash table that uses an array of linked lists to retrieve commands from an outside input file, carry them out, and print the result to an outside output file. The program I've completed compiles well enough but it doesn't run correctly. It pauses for a while, then it says it encountered an error and has to close, but it doesn't specify what the problem is. I tried to use Visual C++'s debugger to solve the problem, and what it says is "Unhandled exception in program.exe: 0xC0000005: Access Violation." It then points to this line of code:
strarray[index] = addnode(strarray[index], item, strarray[index]->refcount);. I have no idea what's wrong with it and the debugger is like a foreign language to me, so if anyone could maybe help me figure this out, that would be much appreciated. This is the code for the program. CPP / C++ / C Code:
The input file is a Notepad file with this text: Code:
Thanks again for any help anyone can provide. Last edited by dsmith : 24-Jul-2005 at 12:44.
Reason: Please use [c] && [/c] for C code syntax
|
|
#2
|
|||
|
|||
|
Quote:
Since the program compiles OK, make the program tell you what's wrong. Debuggers are marvelous tools, but the best debugging tool is the little gray cells that you already know how to use. OK, I will help a little: these are wrong: CPP / C++ / C Code:
command and item are arrays of char. When you use the name of an array (without any []) it is treated as a pointer to char. Therefore the scanf arguments should be changed to looksomething like this: CPP / C++ / C Code:
I recommend that you check the return value of scanf functions every time you call them, so, maybe the program starts like this: CPP / C++ / C Code:
Get the idea? Make the program tell you everything that it does. You can take out the extra printf() statments later (or make comments out of them), so that the screen is not cluttered. (Also check the return values of other system functions, like fopen().) Now, if you proceed in this manner, and if the files opened OK, you will probably get a program crash somewhere along the line, after some print statement that tells you how far you got. Maybe there are other bugs, and maybe not, but you can make the program tell you what it's doing at each step and if it's not what you had in mind: you can see where you need to fix it. Regards, Dave Last edited by davekw7x : 24-Jul-2005 at 20:50.
|
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 13:31 |
| Hash Table & Graph | Kay Chan | C++ Forum | 7 | 08-Oct-2004 08:44 |
| C I/O problem | kelly80 | C Programming Language | 4 | 27-Apr-2004 21:15 |
| customizing preprocessor and hash table | incognito54 | C Programming Language | 2 | 21-Apr-2004 19:25 |
| [Tutorial] MySQL Basics | nniehoff | MySQL / PHP Forum | 15 | 23-Mar-2003 20:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The