Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Owie

another linked list pooch

This topic is 5932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a linked list and it seems to have something wrong. (obviously) I call a function to input my database file (just a simple comma delimited database) and it loads up my records/fields into a linked list. It then calls another function that outputs and converts the records to a fixed width database file. My problem is this, sometime during the output it changes a pointer or messes around with the stored data to make that block of data a repeating 20 (hex) (eg. 2020202020202020). This always happens in the last 10 records. I have checked the input function, and when it stores the data from the original file, it stores just fine. But it will get to a certain record and then *poof* it is 202020202020. Any Ideas?

Share this post


Link to post
Share on other sites
Advertisement
Insufficient memory allocation perhaps. Maybe an "off by one" someplace. If you have a good debugger, trace the pertinent variables looking for the bunk pointer or what not.

Share this post


Link to post
Share on other sites
I did find my problem but it doesnt make any sense whatsoever. I found that in one of my holding strings it was writing past the stringlength to another part of memory. I dont know why this could be so. I initialized the string as:

char *Holding = new char(258);

and when I tried to write:

Holding[170] = '' '';
and it showed up overwriting part of my linked list.

I used ''malloc'' instead of ''new'' to initialize the string and it worked fine though.
Any thoughts?

Share this post


Link to post
Share on other sites
quote:
Original post by Owie

char *Holding = new char(258);




If that is from your source file it should be:

char *Holding = new char[258];
^ ^ <-- note "[]" not "()"

else you would get one new char allocated and initilized to the value 258 that would overflow and give you 2

Edited by - DigitalDelusion on February 26, 2002 1:40:49 PM

Share this post


Link to post
Share on other sites
If you are using a fixed length you might as well not malloc/new the char array at all.

char Holding[258];

Reg''ds,
Steve

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!