Dec 15, 2013 at 5:22pm Dec 15, 2013 at 5:22pm UTC
For school I have to write a program in C++ that utilizes linked lists. I've got it working for the most part but the code is very long. The problem is that whenever I try to do something it gives me Unhandled exception at 0x10201f98 (msvcp100d.dll) in Linked Lists.exe: 0xC0000005: Access violation reading location 0xfeeefeee. It happens whenever I try to display the list more than once. This is the code that displays the list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void display_list()
{
current_ptr = head_ptr;
cout << "\nCountry Size\n" ;
cout << "-------- --------\n" ;
do
{
cout.setf(ios::left);
cout << setw(25);
cout << current_ptr->country_name;
cout.setf(ios::left);
cout << setw(10) << current_ptr->area << endl;
current_ptr = current_ptr->next; // point current_ptr to next node
} while (current_ptr != NULL);
system("pause" );
}
Last edited on Dec 15, 2013 at 5:57pm Dec 15, 2013 at 5:57pm UTC
Dec 15, 2013 at 8:36pm Dec 15, 2013 at 8:36pm UTC
You need run that in a debugger and keep an eye on current_ptr and what it points to.
Dec 15, 2013 at 8:45pm Dec 15, 2013 at 8:45pm UTC
After it is displayed once, current_ptr points to <Bad Ptr> and -17891602.
Dec 15, 2013 at 11:14pm Dec 15, 2013 at 11:14pm UTC
Looks, then, like next is not being set to NULL at the end of the list but rather just left uninitialized.
Dec 16, 2013 at 10:24pm Dec 16, 2013 at 10:24pm UTC
I know the next is being set to NULL, it's just that once I loop through the list once it gives me that error.
Dec 17, 2013 at 11:14am Dec 17, 2013 at 11:14am UTC
"Fee fee" is used by Microsoft's debug HeapFree() to mark freed heap memory.
Dec 17, 2013 at 1:01pm Dec 17, 2013 at 1:01pm UTC
I had accidentally called a function that deleted the list inside my while loop, when it needed to be outside of it.