hi below is code it is only a part of my program simplified for understanding the main problem i am facing ....................
actually the code runs well but while exiting from main displays Null pointer assignment . May i please request the forum member to debug the program..... the code is given below
I am using Turbo c++ version 3.0 compiler
#include<iostream.h>
#include<process.h>
#include<stdio.h>
struct list
{int data;
list *next;
list *previous;
};
class integer
{
char *p;
list *head;
public:
integer()
{head=NULL;
p=NULL;
}
~integer()
{list *tmp=head;
while(tmp!=NULL)
{tmp=tmp->next;
delete(tmp->previous);
}
head=tmp;
delete(p);
}
friend ostream& operator <<(ostream &, integer &);
friend istream& operator >>(istream &,integer &);
integer& operator +(integer&);
};
ostream& operator << (ostream& o,integer& x)
{ list *tmp=x.head;
if(tmp==NULL)
{ o<<"Integer Has Not Been Assigned Any Value"<<endl;
return o;
}
while(tmp!=NULL)
{ o<<tmp->data;
tmp=tmp->next;
}
return o;
}
istream& operator >> (istream& i,integer& x)
{list *tmp=x.head;
char *k=NULL;
i>>x.p;
k=x.p;
if(tmp!=NULL)
{ while(tmp->next!=NULL)
tmp=tmp->next;
while(tmp->previous!=NULL)
{tmp=tmp->previous;
delete(tmp->next);
}
delete(x.head);
x.head=NULL;
}
while(*k!='\0')
{if(x.head==NULL)
{
tmp=new(list);
if(tmp==NULL)
{cout<<"No Memory For Allocation"<<endl;
exit(0);
}
tmp->previous=NULL;
tmp->next=NULL;
x.head=tmp;
tmp->data=*k - 48;
k++;
}
else
{
tmp->next=new(list);
if(tmp==NULL)
{cout<<"No Memory For Allocation"<<endl;
exit(0);
}
tmp->next->previous=tmp;
tmp=tmp->next;
tmp->next=NULL;
tmp->data=*k - 48;
k++;
}
}
return i;
}
void main(void)
{integer k;
cin>>k;
cout<<k;
}