Jul 7, 2011 at 5:56am UTC
/******************STRUCT DEFINATION*************************/
struct linkqueue
{
string addr;
struct linkqueue *link;
};
struct linkqueue *start = NULL;
/***********************FUNCTION TO CREATE A NODE*************/
void insert(struct linkqueue **q, string addr)
{
struct linkqueue *start;
struct linkqueue *temp;
start = *q;
temp = (struct linkqueue *) malloc (sizeof(struct linkqueue));
temp->addr = addr;
temp->link = NULL;
if(*q == NULL)
{
*q == temp;
}
else
{
while(start->link != NULL)
{
start = start->link;
}
start->link = temp;
}
}
/******************MAIN FUNCTION WHERE A STRING IS SENT TO BE INSTERTED INTO LINKED LIST****************/
void linkstore (string addr)
{
int i = 0;
while (addr[i] != '\0')
{
cout<<addr[i];
++i;
}
cout<<"\n";
insert(&start, addr);
}
Last edited on Jul 7, 2011 at 5:58am UTC
Jul 7, 2011 at 6:00am UTC
The error is caused in the line I've written in Bold letters , this is probably some kind of illegal memory assignment dealing with strings.
Jul 8, 2011 at 12:32pm UTC
The error is at line
temp = (struct linkqueue *) malloc (sizeof(struct linkqueue));
please use new to allocate memory
temp =new struct linkqueue;
Thanks
.Madan