| | |
general protection error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2005
Posts: 61
Reputation:
Solved Threads: 0
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:
<< moderator edit: fixed
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;//problem is here
node1* temp2 = (node*)malloc(sizeof(node1*));
temp2->value=val;
temp2->next=head->next;
head->next=temp2;
}[code][/code] tags >> Last edited by Dave Sinkula; Nov 16th, 2005 at 11:25 am.
Turbo*** is 15 year old compiler and does not conforms to most of the standards..stop using it asap....you can download the DEV C++ IDE which uses GCC as it's compiler from here
http://www.bloodshed.net/devcpp.html
http://www.bloodshed.net/devcpp.html
•
•
•
•
Originally Posted by johnray31
and what about general protection error
•
•
Join Date: Jul 2005
Posts: 1,686
Reputation:
Solved Threads: 265
It looks as though you are using the node * called head to be the first node in the list. Once there is an actual node associated with the pointer you don't want to change it, unless you want to make a new head node. The reason to point this out is the following:
for(int y=1; y<x; y++)
head=head->next;//problem is here
Here you change the value of head x times through the loop. I doubt that was your intention. Since you want to insert the new item at position x, I would recommend declaring a new node * to run the list. Start by assigning head to the new pointer. Then chang the value of the new pointer to next each time through the loop. When you get where you want to go, then insert the new node.
for(int y=1; y<x; y++)
head=head->next;//problem is here
Here you change the value of head x times through the loop. I doubt that was your intention. Since you want to insert the new item at position x, I would recommend declaring a new node * to run the list. Start by assigning head to the new pointer. Then chang the value of the new pointer to next each time through the loop. When you get where you want to go, then insert the new node.
Again, don't use <iostream.h>. Plus main() returns int.
Don't cast malloc() (in C; in C++ you should use
In C++, <stdio.h> should become <cstdio>. And the last two headers you shouldn't use (at least not in Dev-C++).
Don't cast malloc() (in C; in C++ you should use
new). And be sure to free() (for malloc()) or delete (for new) your memory. #include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<alloc.h> dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
-1
#8 27 Days Ago
i am gtng general protection error in this program while i run it
plz help!!!!
#include<iostream>
using namespace std;
struct node
{
int seq;
node *next;
};
int main()
{
node *fresh,*temp,*ptr,*save,*start=NULL,*temp1,*start1=NULL;;
int i=0,c,s=1,se,sq;
while(i<5)
{
if(start==NULL)
{
fresh=new node;
cout<<
plz help!!!!
#include<iostream>
using namespace std;
struct node
{
int seq;
node *next;
};
int main()
{
node *fresh,*temp,*ptr,*save,*start=NULL,*temp1,*start1=NULL;;
int i=0,c,s=1,se,sq;
while(i<5)
{
if(start==NULL)
{
fresh=new node;
cout<<
![]() |
Similar Threads
- Help!!!!!! General Protection Exception (C++)
- IEXPLORE caused a general protection fault (Web Browsers)
- General Protection Exception Error Please Help! (C++)
- I keep getting an error message on my computer called General Protection Exception... (C++)
- Windows Protection Error (Windows 95 / 98 / Me)
- windows protection error (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: Error - Going from Java to C++
- Next Thread: N Queen
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






