求教大神,下面这个程序应该怎样输入才能正确运行?说实话,刚学习结构体的我一脸懵逼
#include<stdio.h>#include<string.h>
struct student
{ char name[20];
int num;
char sex;
char department[20];
}stu[20];
int main()
{ struct student t;
int i,j,n,s=0;
char m[20];
scanf("%d",&n);
printf("\tname\tnum\tsex\tdepartment\n");
for(i=0;i<=n-1;i++)
scanf("\t%s\t%d\t%c\t%s",stu[i].name,&stu[i].num,&stu[i].sex,stu[i].department);
printf("按学号输入:\n");
for(i=1;i<=n-1;i++)
for(j=0;j<=n-1-i;j++)
{if(stu[j].num>stu[j+1].num)
{ t=stu[j];
stu[j]=stu[j+i];
stu[j+1]=t;
}
}
for(i=0;i<=n-1;i++)
{ printf("\t%s\t%d\t%c\t%s\n",stu[i].name,stu[i].num,stu[i].sex,stu[i].department);
}
printf("department:\n");
scanf("%s",&m);
for(i=0;i<=n-1;i++)
{if(strcmp(m,stu[i].department)==0)
s++;
}
printf("%d\n",s);
return 0;
}