#include
#include
#define M 4
struct student
{
int num;
float weight;
float height;
float score;
};
int main()
{
int m,n,i,j,k;
struct student st[M];
while(1)
{
printf("1:输入\t2:查看\t3:退出\n");
printf("请输入: ");
scanf("%d",&m);
getchar();
if(1==m)
{
printf("您要输入几个学生的信息?");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d\t%f\t%f\t%f\n",&st[i].num,&st[i].weight,&st[i].height,&st[i].score);
}
if(2==m)
{
for(i=0;i<n;i++)
printf("%d\t%f\t%f\t%f\n",st[i].num,st[i].weight,st[i].height,st[i].score);
}
if(3==m)
goto out;
}
out:
return 0;
}
你的输入是使用制表符来分割的么?调试下。
输出可以使用制表符来分隔,但是输入scanf不能添加额外的东西,应该使用
if (1 == m)
{
printf("您要输入几个学生的信息?");
scanf_s("%d", &n);
for (i = 0; i < n; i++)
{
scanf_s("%d%f%f%f", &st[i].num, &st[i].weight, &st[i].height, &st[i].score);
printf("输入第%d个学生信息完成\n", i+1);
}
}