Advertisement

Access violation

Started by March 26, 2003 05:52 PM
13 comments, last by adam17 21 years, 10 months ago
d3dicated could u clarify what you meant by "pushing" items onto the list?
An access violation happens when you try to access memory that is not valid or out of bounds.

The way you create your list in the first loop is wrong. At each step of the loop you create a new instance of str2 but you do not link them together (with the *str2_pnext pointer that is). At the end of the first loop, the only address that you have is the last allocated str2 in Str2 (but its str2_pnext is not initialized) and the other items are lost in memory (memory leaks). Your second loop looks ok.

Like RipTorn said, don''t blame easy errors on a broken compiler It''s a good time to start using the debugger. Good luck.
--------------------------------------Halcyon
Advertisement
ok i have revamped my code but i am still getting the same access violation. i have also pinpointed the problem. what is happening is im reading in a file via ''>>''s. i read a number into a string and then convert it with the atoi() function and ''c_str()'' is attatched. i know for a fact that the code is reading in the number 8 and its the first number it can read. the error is coming from the atoi() function. any ideas on how i can fix this? its almost as if the function cant convert the number.
First of all, memory leaks cannot be detected by the OS, and they never give run time errors. They just dirty up your memory untill you restart your computer.

I think your problem is that you are trying to access a NULL pointer or a pointer that you created and never set to anything.
When you traverse your linked list u should always check for NULL pointers.
Hi adam!

You should delete the pointer Str2 at the end of your program. I think thats the only problem with your code. After the usage of the "new" keyword you have to destroy the pointer by yourself.

mfg
Patrick

This topic is closed to new replies.

Advertisement