用结构体建立成绩档案再重复输出,循环部分有问题
代码如下#include
#include
#include
struct student
{
char Num[10];
char Name[15];
int type;
int total;
};
int main()
{
struct student stud1[100];
int i,j,n;
int x=1;
char k[10];
printf("input how many student you need to input:");
scanf("%d",&n);
printf("input number\tname\tstudenttype(major 1. in science 2.in arts)\ttotal:\n");
for(i=0;i<N;I++)
{
scanf("%s\t",&stud1[i].Num);
scanf("%s\t",&stud1[i].Name);
scanf("%d\t",&stud1[i].type);
scanf("%d\t",&stud1[i].total);
}
printf("\n");
if(x==1)
{
printf("input the number you search:");
scanf("%s",&k);
printf("\n");
for(i=0;i<N;I++)
{
if(strcmp(stud1[i].Num,k)==0)
{
printf("%s\t",stud1[i].Num);
printf("%s\t",stud1[i].Name);
printf("type %d\t\t",stud1[i].type);
printf("%d",stud1[i].total);
printf("\n");
}
}
printf("input 1 to input again or 2 to out:");
scanf("%d",&x);
printf("\n");
}
return 0;
}