hello guys
here is a problem when i was written a simple demonstrative linklist program
i got the general protection error
(**one more question i need ur guide
i have the turbo c++ compiler but this does not support
when i write #include <iostream>
using namespace std;
plz tell me about latest version of compiler where i can write above statement
)
could u guide me what this error means and when it occur and
what is the solution ?
my code is as:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct node
{
int value;
struct node *next;
}node1;
node1* head=NULL;
void buildlink(node*);
void showlink();
void addition();
void main()
{
for (int x=0; x<4; x++)
buildlink(head);
showlink();
addition();
}
void buildlink(node *linknode)
{ int temp;
cout<<"enter ur node value"<<endl;
cin>>temp;
if(linknode==NULL)
{
head = (node1*)malloc(sizeof(node1*));
head->value=temp;
head->next = NULL;
}
else
{
while(linknode->next)
linknode=linknode->next;
linknode->next=(node1*)malloc(sizeof(node1*));
linknode->next->value=temp;
linknode->next->next=NULL;
}
}
void showlink()
{
while(head)
{
cout<<head->value<<endl;
head=head->next;
}
}
void addition()
{ int x,val;
cout<<"enter position u want to make addition and value "<<endl;
cin>>x>>val;
for(int y=1; y<x; y++)
head=head->next;[B]//problem is here[/B]
node1* temp2 = (node*)malloc(sizeof(node1*));
temp2->value=val;
temp2->next=head->next;
head->next=temp2;
}
<< moderator edit: fixed [co[u][/u]de][/co[u][/u]de]
tags >>