![]() |
|
#1
|
|||
|
|||
bus error in linked listhi,
the program below is supposed to read data out of a txt file into an array and the second part of the data to a linked list. 8 is the number of words, the 10 terms below represent relations between the words, but this is not important. the txt file looks like this: 8 Auto Fahrzeug Maschine Boot Nachen Kraftfahrzeug Blechkiste Gegenstand >H Fahrzeug Auto >H Fahrzeug Boot >S Auto Kraftfahrzeug >S Auto Blechkiste >S Boot Nachen >S Nachen Boot >H Maschine Auto >Y Auto Fahrzeug >Y Boot Fahrzeug >Y Fahrzeug Gegenstand the problem is in the last part of the program, the linked list. the program compiles good, but everytime i run it, it makes a bus error. i´ve tried so many things, but it just keeps doing it. maybe there´s a logic mistake in the list or something i can´t see and someone else will see right up. please help me with this one, i need this program to run as soon as possible. thanks!!!! bastian CPP / C++ / C Code:
Last edited by LuciWiz : 08-Oct-2004 at 04:35.
Reason: Please insert your C++ code between [c++] [/c++] tags
|
|||
|
#2
|
|||
|
|||
|
Quote:
I am going to try to help you get this program to run "as soon as possible" Put printf() statements at various places to see how the program is getting before it bombs out. For example if you know it is reading the words correctly (the program has printed them out correctly after reading the file). You might try the following: CPP / C++ / C Code:
Now, look at what happens when you execute this. It not only tells you how far it got, the values that it prints can tell you why there is a problem. Now, if you fix whatever caused this problem, there may be other things happening that you don't understand. If so, use the same technique to track down the bugs as you find them. printf() is a very powerful debugging tool. Why do I claim that this gets you there "as soon as possible"? Well, I believe that this will be faster than posting a request for help and waiting for a helpful response. If you have any specific questions about the actions, people on this forum are usually willing to try to help. Regards, Dave |
|
#3
|
|||
|
|||
|
hi,
CPP / C++ / C Code:
both strcpy destination strings above are dynmaic storages and you have not allocated memory for them before writing into them. Program is trying to write in some random memory location and crashing. You need to allocated memory for neu->word and neu->dest using either malloc or calloc. CPP / C++ / C Code:
|
Recent GIDBlog
Problems with the Navy (Officers) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Merge sort on a linked list | Temujin_12 | C++ Forum | 1 | 06-Mar-2008 20:33 |
| Insert problem in linked list with two function code | Kay Chan | C++ Forum | 1 | 03-Sep-2004 09:52 |
| Question about linked list and queue | Kay Chan | C++ Forum | 7 | 02-Sep-2004 09:27 |
| help on linked lists any1????? | nick4 | C Programming Language | 1 | 17-May-2004 09:32 |
| [include] list1.h -- Linked list class | dsmith | C Programming Language | 2 | 04-May-2004 09:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The