|
楼主 |
发表于 2005-11-1 13:29:13
|
显示全部楼层
head.h:
#define SIZE 3
#define NAME 20
struct student
{
int num;
char name[NAME];
float score[SIZE];
};
main.c:
#include"head.h"
#include"input.c"
int main()
{
void input(struct student *);
void output(struct student *);
struct student stu[SIZE];
struct student *ptr;
ptr = stu;
input(ptr);
output(ptr);
}
input.c:
#include<stdio.h>
void input(struct student *ptr)
{
int i, j;
for (i = 0; i < SIZE; i++)
{
j = 0;
printf("Enter the member of the stu.\n");
printf("No: ");
scanf("%d", &ptr->num);
printf("Name: ");
gets(ptr->name); //就是这里啊!!!!用gets()函数后,没有执行输入,就直接运行到scanf()去了,不
//过用scanf()可以输入,可是不能有空格啊,不知道什么原因.望赐教!!!!谢谢!!
printf("Course 1: ");
scanf("%f", &ptr->score[j]);
printf("Course 2: ");
scanf("%f", &ptr->score[++j]);
printf("Courese 3: ");
scanf("%f", &ptr->score[++j]);
//printf("\n");
ptr++;
}
} |
|