Access violation
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.
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

--------------------------------------Halcyon
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement