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:

	typedef struct node
		int value;
		struct node *next;
	node1* head=NULL;
	void buildlink(node*);
	void showlink();
	void addition();
  void main()
		for (int x=0; x<4; x++)
	void buildlink(node *linknode)
	 {  int temp;
		 cout<<"enter ur node value"<<endl;

			 head = (node1*)malloc(sizeof(node1*));
			 head->next = NULL;

	  void showlink()
	  void addition()
		{  int x,val;
			cout<<"enter position u want to make addition and value "<<endl;
			for(int y=1; y<x; y++)
			 head=head->next;[B]//problem is here[/B]
          node1* temp2 = (node*)malloc(sizeof(node1*));

<< moderator edit: fixed [co[u][/u]de][/co[u][/u]de] tags >>

and what about general protection error

First download that IDE...try running in it....i am sure it will give more errors and warning(though not tested ur code yet).......there are many issues with ur code....to start with....u r mixing stdio with iostream...u should not do that....using void main which is wrong....it should be int main.....make those changes and run it.....then see what error it gives

now i have installed that id and make some change as u said
it compile successfully and when i execute it
it gives some error and say ur file have to be closed due to a error
plz look it

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.

Again, don't use <iostream.h>. Plus main() returns int.

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.


In C++, <stdio.h> should become <cstdio>. And the last two headers you shouldn't use (at least not in Dev-C++).

i am gtng general protection error in this program while i run it
plz help!!!!

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;
                                    fresh=new node;

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.