求仔细分析这段代码
#include<stdio.h>main()
{
char choice;
printf("==================================学生选课系统==================================\n");
printf("*******************************************************************************\n");
printf("1.录入课程信息\n");
printf("2.选课\n");
printf("3.课程信息浏览\n");
printf("4.查询\n");
printf(" 0:exit\n");
printf("\n");
printf("*******************************************************************************\n");
printf(" Please make a choice\n");
do
{
choice=getchar();getchar();
switch(choice)
{
case'1':function1();break;
case'2':function2();break;
case'3':function3();break;
case'4':function4();break;
case'0':exit(0);
}
}
while(1);
}
int function1()
{
FILE *fp;/*文件指针类型变量*/
char string [30];
if((fp=fopen("F:\\C3exe\\file1.txt","w"))==NULL) /*文件file1.txt的路径,在程序中写成“F:C3exe\\file1,txt,用”\\“表示”\“*/
{
printf("can't open file");
exit(1);
}
while(strlen(gets(string))>0)
{
fputs(string,fp);
fputs("\n",fp);
}
fclose(fp);
}
struct XK/*结构体类型,将不同数据组织起来*/
{
int num;
char name[10];
char type[10];
int sumtime;
int teachtime;
int practisetime;
int score;
int term;
}kecheng[10];
int function2()
{
struct XK kecheng[3]={{0,"chinese","wenke",40,30,10,20,1},
{1,"maths","like",50,40,10,30,1},
{2,"english","wenke",40,40,0,30,1}};
int sum=0,i,n,j;
for(j=0;j<=10;j++)
{
printf("请输入要选择的课程号:");
scanf("%d",&n);
for(j=0;j<=10;j++)
{
if(kecheng[j].num==n)
{
sum=sum+kecheng[j].score;
if(sum>=60)
printf("选课成功");
exit(1);
}
else
{
continue;
}
}
}
}
int function3()
{
FILE *fp;
char string[30];
if((fp=fopen("F:\\C3exe\\file1.txt","r"))==NULL)
{
printf("can't open file");
exit(1);
}
while(fscanf(fp,"%s")!=EOF)
printf("%s\n");
fclose(fp);
exit(1);
}
struct Student
{
int num;
char name[20];
char type[20];
int sumtime;
int teachtime;
int practisetime;
int score;
int term;
}score[10];
int function4()
{
struct Student score[10]={{0,"chinese","wenke",40,30,10,20,1},
{1,"math","like",50,40,10,30,1},
{2,"english","wenke",40,40,0,30,1}};
int i,n;
for(i=0;i<10;i++)
{
printf("输入要查询的学分:");
scanf("%d",&n);
if(score[i].score==n);
printf("%5d%9s%9s%5d%5d%5d%5d%5d",score[i].num,score[i].name,score[i].name,score[i].type,score[i].sumtime,score[i].teachtime,score[i].practisetime,score[i].score,score[i].term);
exit(1);
}
}