Hi,
These two functions just try to accept some input then store it on a linked list...no errors..but when it runs..the whole thing just crashed! why???
-----------------------------------------------------------------------------------void enter(void)
{
struct address *info;
for(;
{
info=(struct address *)malloc(sizeof (list_entry));
if(!info)
{
printf("\nout of memory");
return;
}
printf("Enter a string:",info ->name,30);
if(!info->name [0])break;
dls_store (info, &start, &last);
}
}
----------------------------------------------------------------------------------
void dls_store(struct address *i, struct address **start, struct
address **last)
{
struct address *old, *p;
if (*last==NULL)
{
i->next=NULL;
i->prior=NULL;
*last=i;
*start=i;
return;
}
p=*start; //start at the top of list
old=NULL;
while (p)
{
if (strcmp(p->name,i->name)<0)
{
old=p;
p=p->next;
}
else
{
if(p->prior)
{
p->prior->next=i;
i->next=p;
i->prior=p->prior;
p->prior=i;
return;
}
i->next=p; //new first element
i->prior=NULL;
p->prior=i;
*start=i;
return;
}
}
old->next=i;
i->next=NULL;
i->prior=old;
*last=i;
}
----------------------------------------------------------------------------------