![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Problem with the function creating updating a linked listHi all,
I have this function,which builds dynamic linked list from the data received in connections. It complies fine. But when I build the first node in the list, the next pointer is somehow now getting assigned to NULL, which causes my while loops where in I check for NULL value, go on indefinitely. Following my function. I guess it must be something simple that i am missing but just cant figure out where. Pls help. I have sprinkled lots of printf statment in function for debugging purpose. CPP / C++ / C Code:
this how I am defining queue and queue pointer variables in the parent function and calling this function. CPP / C++ / C Code:
Any suggestions ? Thanks, |
|
#2
|
|||
|
|||
|
Quote:
I haven't looked at everything, but I don't think you are malloc'ing what you need. For example, you are getting storage for the struct, but you have CPP / C++ / C Code:
Shouldn't this be CPP / C++ / C Code:
??? Look at your other malloc() stuff also. Regards, Dave |
|
#3
|
|||
|
|||
|
Thanks dave,
That was the problem, I guess? I got little confused there with pointer to pointer convension that I didn't realize it. However I still wonder how it worked for first and second call to the function. I tried printing queue in the parent function and it kept printing the first connection data cause NULL was never hit. I guess, i was just lucky not to see a crash. Thanks, |
|
#4
|
|||
|
|||
|
Quote:
When a pointer points outside of its allocated area, it points somewhere. If it happens to point to some other allocated area, things may seem to be OK --- until the rightful owner of that area uses it (or tries to use it). Then all heck breaks loose --- sometimes. Sometimes everything seems to be OK, but then at some later date it falls apart. Sometimes everything seems to work OK with a given set of test data, but then blows up when actual user data is encountered. In your case you were lucky to have it misbehave with a fairly small test. The bottom line: test, test, test, but remember that you can't prove a program is correct just by testing. Good Luck, and Best regards, Dave |
Recent GIDBlog
Developing GUIs with wxPython (Part 2) 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 |
| help on linked lists any1????? | nick4 | C Programming Language | 1 | 17-May-2004 09:32 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The