主题:结构体问题
#include<stdio.h>
#define N 3
typedef struct stu
{
int num;
char name[10];
float score[3];
} STUDENT;
void InputData(STUDENT *s)
{
int i,j;
for(i=0;i<3;i++)
{printf("please input the student's number:\n");
scanf("%d",&s[i].num);
printf("please input the student's name:\n");
scanf("%s",s[i].name);
printf("please input the student's three scores:\n");
for(j=0;j<3;j++)
scanf("%d%d%d",&s[i].score[j]);
getchar();
}
}
void OutputData(STUDENT *s)
{
int i,j;
for(i=0;i<3;i++)
{
printf("%3d%10s",s[i].num,s[i].name);
printf("%3f%3f%3f",s[i].score[0],s[i].score[1],s[i].score[2]);
}
}
void main(void)
{
STUDENT s[N];
clrscr();
InputData(s);
OutputData(s);
getch();
}
&s[i].score[j这个取地址方法是否正确,如果不对如何改正?目的是输入几个人的几门课成绩输出,大家帮忙看看错在那了,谢谢!
#define N 3
typedef struct stu
{
int num;
char name[10];
float score[3];
} STUDENT;
void InputData(STUDENT *s)
{
int i,j;
for(i=0;i<3;i++)
{printf("please input the student's number:\n");
scanf("%d",&s[i].num);
printf("please input the student's name:\n");
scanf("%s",s[i].name);
printf("please input the student's three scores:\n");
for(j=0;j<3;j++)
scanf("%d%d%d",&s[i].score[j]);
getchar();
}
}
void OutputData(STUDENT *s)
{
int i,j;
for(i=0;i<3;i++)
{
printf("%3d%10s",s[i].num,s[i].name);
printf("%3f%3f%3f",s[i].score[0],s[i].score[1],s[i].score[2]);
}
}
void main(void)
{
STUDENT s[N];
clrscr();
InputData(s);
OutputData(s);
getch();
}
&s[i].score[j这个取地址方法是否正确,如果不对如何改正?目的是输入几个人的几门课成绩输出,大家帮忙看看错在那了,谢谢!