那儿错啦?
#include<stdio.h>#include<string.h>
struct student
{int num;
char name[20];
float score[3];
};
void main()
{void print(struct student *s);
struct student stu[5];
int i,j;
for(i=0;i<5;i++)
{printf("\nInput score of stuent %d:\n",i+1);
printf("NO.");
scanf("%d",&stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{printf("score%d:",j+1);
scanf("%f",&stu[i].score[j]);
}
printf("\n");
}
print(stu);
}
void print(struct student *s)
{
int i;
for(i=0;i<5;i++,s++)
printf("%d\t%s\t%f\t%f\t%f\n",(*s).num,(*s).name,(*s).score[0],(*s).score[1],(*s).score[2]);
}
搜索更多相关的解决方案:
include
----------------解决方案--------------------------------------------------------
没人看,不值钱!
#include<stdio.h>#include<string.h>
struct student
{int num;
char name[20];
float score[3];
};
void main()
{void print(struct student *s);
struct student stu[5];
int i,j;
for(i=0;i<5;i++)
{printf("\nInput score of stuent %d:\n",i+1);
printf("NO.");
scanf("%d",&stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{printf("score%d:",j+1);
scanf("%f",&stu[i].score[j]);
}
printf("\n");
}
print(stu);
}
void print(struct student *s)
{
int i;
for(i=0;i<5;i++,s++)
printf("%d\t%s\t%f\t%f\t%f\n",(*s).num,(*s).name,(*s).score[0],(*s).score[1],(*s).score[2]);
}
那儿错啦?
----------------解决方案--------------------------------------------------------
应该是楼主你粗心,掉了一个取地址运算符:
#include<stdio.h>
#include<string.h>
struct student
{int num;
char name[20];
float score[3];
};
void main()
{void print(struct student *s);
struct student stu[5];
int i,j;
for(i=0;i<5;i++)
{printf("\nInput score of stuent %d:\n",i+1);
printf("NO.");
scanf("%d",&stu[i].num);
printf("name:");
scanf("%s",&stu[i].name);
for(j=0;j<3;j++)
{printf("score%d:",j+1);
scanf("%f",&stu[i].score[j]);
}
printf("\n");
}
print(stu);
}
void print(struct student *s)
{
int i;
for(i=0;i<5;i++,s++)
printf("%d\t%s\t%f\t%f\t%f\n",(*s).num,(*s).name,(*s).score[0],(*s).score[1],(*s).score[2]);
}
----------------解决方案--------------------------------------------------------
回复 3# 的帖子
scanf("%s",stu[i].name);这个没有错 ,stu[i].name是 字符变量名,不加 &这个程序如果把
struct student
{int num;
char name[20];
float score[3];
};
中的float score[3];改为 int型及后面的程序作相应更改则运行结果 正确
负责编译 能通过,但运行时异常终止!
----------------解决方案--------------------------------------------------------
为什么我运行是没错的呢?
----------------解决方案--------------------------------------------------------