请C语言高手帮忙解释一下这个程序的每句话!!!!!!!!!!!!!!!!!!!

#include <stdio.h>
#define SIZE 1000
struct student
{
char name[10];
char sex[1];
char coll[15];
char kind[15];
int num;
};

int choice();
int Input();
void Print();
int add();
int m,n;
void PrintOne();
void Modify();
void Del();

void main()
{
struct student stu[SIZE];
int c;
do
{
clrscr();
c=choice();
switch(c)
{
case 0:printf("\nWelcome to this program!");break;
case 1:m=Input(stu);break;
case 2:add(stu);break;
case 3:Print(stu);break;
case 4:Del(stu);break;
case 5:PrintOne(stu);break;
case 6:Modify(stu);break;
}
}while(c);
}

void DisplayMenu()
{
printf("\n\t\t PLEASE ENTER A NUMBER FROM 0 TO 6!");
printf("\n\n\n\t****************************************************************");
printf("\n\t\t 1 - Input student's informations");
printf("\n\t\t 2 - Add a student's informations");
printf("\n\t\t 3 - Print all student's informations");
printf("\n\t\t 4 - DeL a student's informations");
printf("\n\t\t 5 - Print a student's information");
printf("\n\t\t 6 - Modify a student's information");
printf("\n\t\t 0 - Exit system");
printf("\n\t****************************************************************");
printf("\n\n\n\n\n\n\t\tChoice the number,please:");
}

int choice()
{
int a;
do
{
DisplayMenu();
scanf("%d",&a);
}
while(a<0||a>6);
return a;
}

int Input(struct student stu[])
{
FILE *fp;
int i;
clrscr();

printf("\n\n\t\t\tHow many do you want to input :");
scanf("%d",&m);

for(i=1;i<m+1;i++)
{
printf("\n\n\t\t\t\t =%d=",i);
printf("\n\tInput student's name :");
scanf("%s",&stu[i].name);
printf("\tInput student's sex(M/F) :");
scanf("%s",&stu[i].sex);

getch();

printf("\tInput student's college :");
scanf("%s",&stu[i].coll);
printf("\tInput student's kind :");
scanf("%s",&stu[i].kind);
printf("\tInput student's number :");
scanf("%d",&stu[i].num);
printf("\n");}
if((fp=fopen("stu_list","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;stu[i].num!=0;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

第1个回答  推荐于2016-05-21
#include <stdio.h> 引用标准库
#define SIZE 1000 宏定义size=1000
struct student 定义一个结构体
{
char name[10];
char sex[1];
char coll[15];
char kind[15];
int num;
};

int choice(); 声明7个函数,2个全局变量m n
int Input();
void Print();
int add();
int m,n;
void PrintOne();
void Modify();
void Del();

void main() 主函数
{
struct student stu[SIZE]; 结构体数组stu
int c;
do 循环,
{
clrscr(); 清屏幕
c=choice(); 运行子函数choice,结果给c
switch(c) 根据c的值,分别执行各个功能
{
case 0:printf("\nWelcome to this program!");break;打印欢迎信息
case 1:m=Input(stu);break; 1到6,调用各个子函数
case 2:add(stu);break;
case 3:Print(stu);break;
case 4:Del(stu);break;
case 5:PrintOne(stu);break;
case 6:Modify(stu);break;
}
}while(c);
}

void DisplayMenu() 这个子函数是显示菜单,各个printf都是直接打印出来
{
printf("\n\t\t PLEASE ENTER A NUMBER FROM 0 TO 6!");
printf("\n\n\n\t****************************************************************");
printf("\n\t\t 1 - Input student's informations");
printf("\n\t\t 2 - Add a student's informations");
printf("\n\t\t 3 - Print all student's informations");
printf("\n\t\t 4 - DeL a student's informations");
printf("\n\t\t 5 - Print a student's information");
printf("\n\t\t 6 - Modify a student's information");
printf("\n\t\t 0 - Exit system");
printf("\n\t****************************************************************");
printf("\n\n\n\n\n\n\t\tChoice the number,please:");
}

int choice() 这个子函数返回结果到主函数
{
int a;
do 循环,
{
DisplayMenu(); 显示菜单
scanf("%d",&a); 接收键盘输入,
}
while(a<0||a>6); 输入条件,0到6,范围不对则重新显示菜单,再输入
return a; 返回a
}

int Input(struct student stu[]) 输入,子函数
{
FILE *fp; 变量定义
int i;
clrscr();

printf("\n\n\t\t\tHow many do you want to input :");
scanf("%d",&m); 输入数量

for(i=1;i<m+1;i++) 做m次循环
{
printf("\n\n\t\t\t\t =%d=",i); 打印当前是第几个人
printf("\n\tInput student's name :"); 提示输入名字
scanf("%s",&stu[i].name); 键盘输入名字
printf("\tInput student's sex(M/F) :");提示输入性别
scanf("%s",&stu[i].sex); 键盘输入性别

getch(); 接受输入

printf("\tInput student's college :"); 输入college
scanf("%s",&stu[i].coll);
printf("\tInput student's kind :"); 输入kind
scanf("%s",&stu[i].kind);
printf("\tInput student's number :"); 输入number
scanf("%d",&stu[i].num);
printf("\n");}
if((fp=fopen("stu_list","wb"))==NULL) 打开文件
{
printf("cannot open file\n"); 如打不开,提示不能打开
return; 返回退出
}
for(i=0;stu[i].num!=0;i++) 循环,
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) 数据写入文件
printf("file write error\n"); 若写入错误则提示,
fclose(fp); 关闭文件
}本回答被提问者采纳
第2个回答  2009-12-28
我靠,这都要!!!
第3个回答  2009-12-28
你是大爷!
第4个回答  2009-12-28
折腾人。。。
相似回答