Hi All,
I am a newbie and am traking a course in Aptech for C++. Now my instructor asked me to make a program to create, display and insert nodes in a circular link list. I have made the following code:

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <new>

class clinklist
{
	public:
		int data;
		clinklist *link;
}*start;

void create();
void display();
void IFB();
void IFE();
void IAD();
void IBD();

using namespace std;

int main()
{
	int choice = 0;
	while(choice != 7)
	{
	system("CLS");
	cout << "Circular Link List" << endl << endl;
	cout << "1. Create" << endl;
	cout << "2. Display" << endl;
	cout << "3. Insert From Beginning" << endl;
	cout << "4. Insert From Ending" << endl;
	cout << "5. Insert After Data" << endl;
	cout << "6. Insert Before Data" << endl;
	cout << "7. Exit" << endl << endl;
	cout << "Enter Your Choice: ";
	cin >> choice;
	switch(choice)
	{
	case 1:
		create();
		break;
	case 2:
		display();
		break;
	case 3:
		IFB();
		break;
	case 4:
		IFE();
		break;
	case 5:
		IAD();
		break;
	case 6:
		IBD();
		break;
	case 7:
		cin.get();
		break;
	}
	}
}

void create()
{
	clinklist *n, *ptr;
	ptr = start;
	n = new (nothrow) clinklist;
	if(n==0)
	{
		cout <<"Memory Could Not Be Allocated";
		cin.get();
		return;
	}
	cout << endl << endl <<"Enter Data For New Node: ";
	cin >> n->data;
	if(start == NULL)
	{
		start = n;
		n->link=start;    
	}
	else
	{
		n->link=start;
		while(ptr->link!=start)
			ptr = ptr->link;
	}
	ptr->link = n;
}

void display()
{
	int i = 1;
	clinklist *ptr = start;
	while(ptr->link != start)
	{
		cout << endl << endl << "Node " << i << ": " << ptr ->data << endl;
		ptr = ptr -> link;
		i++;
	}
	i++;
	cout << cout << "Node " << i << ": " << ptr ->data << endl;
}

void IFB()
{
	cout << "Under Development!" << endl;
}

void IFE()
{
	cout << "Under Development!" << endl;
}

void IAD()
{
	cout << "Under Development!" << endl;
}

void IBD()
{
	cout << "Under Development!" << endl;
}

Now the VS2010 compiler/debugger is showing a problem at line "ptr->link = n;" with the following error message:
Unhandled exception at 0x001019bb in Circular Link List.exe: 0xC0000005: Access violation writing location 0x00000004.
Can anyone tell me the reason ASAP, as I have to submit the code this monday?
Regards,
Shikhin

You need to learn how to use your compiler's debugger so that you can single-step the execution of the program and see for yourself what is causing the problem.

Hint: line 89 is in the wrong place.

Well, Ancient Dragon. I would surely follow your suggestion. However, I dont have the time to learn it. So can you tell me the problem(if you know it)

Yes I know that problem -- and I already told you what it is. Your program has other problems too that you will discover after you learn how to debug your program. Asking us to debug your program for you is a huge waste of your time.

Basic debugging isn't that difficult. Set a break point (where execution of the program will stop) then step through it one line at a time. In VC++ 2010 Express there is a Debug menu that will have options to do that. You can probably learn the basics in less than an hour.

Hi Ancient Dragon. I had to go somewhere before reading your last post so I couldnt read the hint. I apologize for what I said to you. Well after reading the post again I solved the problem. Now as the code is developed I am trying to learn basics of debugging. Thanks Ancient Dragon You are a life saver!!!

PS. I got to find some problems after using a debugger