HI everyone. :) .I hope you can help me my function . I want the user to enter number of level "There are two levels" and then display students records in that level sorted by id .the one I wrote sorts then displays so the output is wrong .I tried to put the sort part after the level check but the program crashed. Any ideas??
here is the code
void displaysortbyID()
{
int levelno;
struct school *pre;
struct school *move;
struct school *temp;
temp = (school *) malloc (sizeof(school));
printf("\nEnter the number of level ");
scanf("%d",&levelno);
move=head;
pre=head;
move=move->next;
while (move!=NULL)
{
if ((pre->id)>(move->id))
{
temp->id=pre->id;
pre->id=move->id;
move->id=temp->id;
}
pre=pre->next;
move=move->next;
} /*End of sorting*/
{ move=head;
while (move!=NULL)
{
if(move->level==levelno)
{printf("\n\n The output is\n ");
printf("\n\n Id : %d",move->id);
printf("\n Name : %s",move->name);
printf("\n Adress : %s",move->address);
printf("\n Phone : %d",move->phone);
printf("\n Sex: %s",move->sex);
printf("\n Level : %d",move-> level);
printf("\n Average : %f",move->average);}
move = move->next;
}// end of while .
}
getch();
}