Visual Studio Access violation reading location 0xfeeefeee

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
You need run that in a debugger and keep an eye on current_ptr and what it points to.
After it is displayed once, current_ptr points to <Bad Ptr> and -17891602.
Looks, then, like next is not being set to NULL at the end of the list but rather just left uninitialized.
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.
closed account (z05DSL3A)
"Fee fee" is used by Microsoft's debug HeapFree() to mark freed heap memory.
I had accidentally called a function that deleted the list inside my while loop, when it needed to be outside of it.
Topic archived. No new replies allowed.