#include<stdio.h>#define N 5struct student{char num[6];char name[8];int score[4];}stu[N];void main(){void pintf(struct student stu[6]);int i,j;for(i=0;i<N;i++){printf("\n请输入学生学号:\n",i+1);printf("No.:");scanf("%s",stu[i].num);printf("名字:");scanf("%s",stu[i].name);for(j=0;j<3;j++){printf("成绩%d:",j+1);scanf("%d",&stu[i].score[j]);}printf("\n");}print(stu);}void print(struct student stu[6]){int i,j;printf("\n No. name 1 2 3\n");for(i=0;i<N;i++){printf("%5s%10s",stu[i].num,stu[i].name);for(j=0;j<3;j++)printf("%9d",stu[i].score[j]);print("\n");}}D:\c\PROG1\prom6\1-1.cpp(34) : error C2065: 'print' : undeclared identifierD:\c\PROG1\prom6\1-1.cpp(38) : error C2373: 'print' : redefinition; different type modifiers就是这样我自己不知道哪里错了,求解答
2 回答
慕妹3242003
TA贡献1824条经验 获得超6个赞
#include<stdio.h>
#define N 5
struct student
{
char num[6];
char name[8];
int score[4];
}
stu[N];
void main()
{
void pintf(struct student stu[6]); /*这边定义的函数名pintf 跟下边引用的不一样*/
int i,j;
for(i=0;i<N;i++)
{
printf("\n请输入学生学号:\n",i+1);
printf("No.:");
scanf("%s",stu[i].num);
printf("名字:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{
printf("成绩%d:",j+1);
scanf("%d",&stu[i].score[j]);
}
printf("\n");
}
print(stu); /*这边函数引用跟上边定义的函数名不一样*/
}
void print(struct student stu[6])
{
int i,j;
printf("\n No. name 1 2 3\n");
for(i=0;i<N;i++)
{
printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9d",stu[i].score[j]);
printf("\n"); /*这边将print 改为printf */
}
}
添加回答
举报
0/150
提交
取消