In your search routine..
for(struct list *trav1=trav2; strcmp(trav1->name,temp2->name)!=0;trav1=trav1->next);
here trav1 will be null at the end of list but you are still going ahead and derefrencing it. Add a check temp1 in your for loop like this:
for(struct list *trav1=trav2; trav1 && (strcmp(trav1->name,temp2->name)!=0);trav1=trav1->next);
Or, for better readability:
for (struct list *trav1 = trav2; trav1 != NULL; trav1 = trav1->next)
{
if (strcmp(trav1->name, temp2->name) !=0 )
break;
}
A few other comments on your code:
Do not use
fflush(stdin)
use something like this since that is not guaranteed by the standard to work.int c; while ((c = getchar()) != EOF && c != '\n') ;
Stop using
gets()
. It is impossible to usegets()
safely. Usefgets()
instead (but be aware it keeps the newline wheregets()
discards it).