Error Linked List

/******************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
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.
The error is at line
temp = (struct linkqueue *) malloc (sizeof(struct linkqueue));

please use new to allocate memory
temp =new struct linkqueue;

Thanks
.Madan
Topic archived. No new replies allowed.