大神帮我看一眼,我的一段作业,求解释,代码如下
#include<stdio.h>
#include<windows.h>
#define AMOUNT 1
char * s_gets(char * st,int n);
struct stl
{
char IDNumber[16];
char FamilyName[16];
char GivenName[16];
int sex;
int BirthYear;
int BirthMonth;
int BirthDay;
float score[4];
float sum;
float average;
};
int main(void)
{
struct stl student[AMOUNT];
int count=0;
int index;
printf("Please enter the student IDNumber.\n");
printf("Press [enter] to stop.\n");
while(count<AMOUNT && s_gets(student[count].IDNumber,16) != NULL && student[count].IDNumber[0] !='\0')
{
printf("Enter the Family name.\n");
s_gets(student[count].FamilyName,16);
printf("Enter the GivenName.\n");
s_gets(student[count].GivenName,16);
printf("enter the sex,0 is woman,1 is man.\n");
scanf("%d",&student[count].sex);
printf("Enter the BirthYear.\n");
scanf("%d",&student[count].BirthYear);
printf("Enter the BirthMonth.\n");
scanf("%d",&student[count].BirthMonth);
printf("Enter the BirthDay.\n");
scanf("%d",&student[count].BirthDay);
printf("Enter the 4 scores.\n");
scanf("%f%f%f%f",&student[count].score[0],&student[count].score[1],&student[count].score[2],&student[count].score[3]);
student[count].sum=student[count].score[0]+student[count].score[1]+student[count].score[2]+student[count].score[3];
student[count].average=student[count].sum/4;
count++;
while(getchar() != '\n')
continue;
if(count<AMOUNT)
printf("Enter the next student.\n");
}
if(count>0)
{
printf("Here is the list of your students:\n");
printf("IDNumber\t Name\t sex\t BirthYear/Month/Day\t score1 score2 score3 score4\t sum\t average\t\n");
for(index=0;index<count;index++)
printf("%5s\t %9s%s\t %3d\t %10d/%d/%d\t %14.1f %4.1f %4.1f %4.1f\t%.2f\t\t%3.1f\t\n",student[index].IDNumber,student[index].FamilyName ,student[index].GivenName,student[index].sex,student[index].BirthYear,student[index].BirthMonth,student[index].BirthDay,student[index].score[0],student[index].score[1],student[index].score[2],student[index].score[3],student[index].sum,student[index].average);
}
else
printf("no student\n");
}
char * s_gets(char * st,int n)
{
char * ret_val;
char * find;
ret_val=fgets(st,n,stdin);
if(ret_val)
{
find=strchr(st,'\n');
if(find)
*find='\0';
else
while(getchar() !='\n')
continue;
}
return ret_val;
}
#include<stdio.h>
#include<windows.h>
#define AMOUNT 1
char * s_gets(char * st,int n);
struct stl
{
char IDNumber[16];
char FamilyName[16];
char GivenName[16];
int sex;
int BirthYear;
int BirthMonth;
int BirthDay;
float score[4];
float sum;
float average;
};
int main(void)
{
struct stl student[AMOUNT];
int count=0;
int index;
printf("Please enter the student IDNumber.\n");
printf("Press [enter] to stop.\n");
while(count<AMOUNT && s_gets(student[count].IDNumber,16) != NULL && student[count].IDNumber[0] !='\0')
{
printf("Enter the Family name.\n");
s_gets(student[count].FamilyName,16);
printf("Enter the GivenName.\n");
s_gets(student[count].GivenName,16);
printf("enter the sex,0 is woman,1 is man.\n");
scanf("%d",&student[count].sex);
printf("Enter the BirthYear.\n");
scanf("%d",&student[count].BirthYear);
printf("Enter the BirthMonth.\n");
scanf("%d",&student[count].BirthMonth);
printf("Enter the BirthDay.\n");
scanf("%d",&student[count].BirthDay);
printf("Enter the 4 scores.\n");
scanf("%f%f%f%f",&student[count].score[0],&student[count].score[1],&student[count].score[2],&student[count].score[3]);
student[count].sum=student[count].score[0]+student[count].score[1]+student[count].score[2]+student[count].score[3];
student[count].average=student[count].sum/4;
count++;
while(getchar() != '\n')
continue;
if(count<AMOUNT)
printf("Enter the next student.\n");
}
if(count>0)
{
printf("Here is the list of your students:\n");
printf("IDNumber\t Name\t sex\t BirthYear/Month/Day\t score1 score2 score3 score4\t sum\t average\t\n");
for(index=0;index<count;index++)
printf("%5s\t %9s%s\t %3d\t %10d/%d/%d\t %14.1f %4.1f %4.1f %4.1f\t%.2f\t\t%3.1f\t\n",student[index].IDNumber,student[index].FamilyName ,student[index].GivenName,student[index].sex,student[index].BirthYear,student[index].BirthMonth,student[index].BirthDay,student[index].score[0],student[index].score[1],student[index].score[2],student[index].score[3],student[index].sum,student[index].average);
}
else
printf("no student\n");
}
char * s_gets(char * st,int n)
{
char * ret_val;
char * find;
ret_val=fgets(st,n,stdin);
if(ret_val)
{
find=strchr(st,'\n');
if(find)
*find='\0';
else
while(getchar() !='\n')
continue;
}
return ret_val;
}