I got a few problems when writing this program. While searching in the list, only the first result can be shown. the program cant show more than one result even if there are other data matching the requirement.
The second problem is that when the user tries to search by name there will be a runtime error.
Thanks for helping.
Here is the code:
int namesearch(LIST *list,STUDENT **pPre,STUDENT **pLoc,char target[]){
int n;
*pLoc = list->head;
for (;*pLoc!=NULL && n!=0;){
n=strncmp(target,(*pLoc)->name,MAXNUM);
*pPre = *pLoc;
*pLoc = (*pLoc)->next;
printf("1");
}
if(*pPre==NULL)
return 0;
else{
printf("2");
if (n==0){
printf("%s%d | %-18s| %0.1f | %0.1f",RESULT,(*pLoc)->sid,(*pLoc)->name,(*pLoc)->ca,(*pLoc)->exam);
return 1;
fflush(stdin);getch();
}
else
printf("3");
return 0;
}
}