c语言学生管理系统程序解释
有些地方看不懂啊,我是菜鸟..可是又要写报告,还要提问..可以把把下面的程序语句的意思大概说下么?】#define LEN sizeof(struct student)
#define FILE_DATA_PATH "c:\student.txt"
由于那程序比较长所以我截我不懂的希望高手给解释啊~拜托
void insert(struct student *stu)
{
struct student *p0, *p1, *p2;
p1 = head;
p0 = stu;
if(head == NULL)
{
head = p0;
p0->next = NULL;
}
else
{
while((p0->num > p1->num)&&(p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(p0->num <= p1->num)
{
if(head == p1)
head = p0;
else
p2->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next = NULL;
}
}
TOTAL_NUM++;
}
void display(struct student *p)
{
printf("%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n", p->num, p->name, p->age, p->易做图, p->birthday, p->address, p->tele_num, p->E_mail);
}
//浏览学生信息
void displayAll()
{
struct student *p;
printf("学生总数:%d\n", TOTAL_NUM);
p = head;
if(head != NULL)
{
printf("\n学号\t姓名\t年龄\t性别\t出生年月\t地址\t电话\tE-mail\n");
printf("-------------------------------------------------------------------------------");
do
{
display(p);
p = p->next;
}
while(p != NULL);
}
printf("\n")
}
追问:大神啊~~你就是我的救星啊~~那啥索性都给我解释了吧嘿嘿~~我把完整的程序给你看吧,需要解释的我用*** 内容 ***标出来好么~#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <io.h>
#define NULL 0
#define LEN sizeof(struct student)
#define FILE_DATA_PATH "c:\student.txt"
struct student
{
long int num;
char name[20];
int age;
char 易做图[4];
char birthday[10];
char address[30];
long int tele_num;
char E_mail[20];
struct student *next;
};int TOTAL_NUM = 0;
struct student *head = NULL;void welcome();
void mainmenu();
void record();
void insert(struct student *stu);
void display(struct student *stu);
void displayAll();
void query();
void query_by_num();
void query_by_name();
void readData();
void writeData();
void freeAll();
void del();
void change();
void devise(struct student *p);int main()
{
char userName[9];
char userPWD[7];
int i;
welcome();
for(i = 0; i < 3; i++)
{
printf("\n管理员初始用户名和密码均为admin\n");
printf("请输入您的用户名:");
scanf("%s", userName);
printf("\n请输入您的密码:");
scanf("%s", userPWD);
if ((strcmp(userName,"admin")==0) && (strcmp(userPWD,"admin")==0))
{
//用户名和密码正确,显示主菜单
mainmenu();
break;
}
else
{
if (i < 2)
{
//用户名或密码错误,提示用户重新输入
printf("用户名或密码错误,请重新输入!");
}
else
{
//连续3次输错用户名或密码,退出系统。
printf("您已连续3次将用户名或密码输错,系统将退出!");
}
}
}
return 0;
}
//显示欢迎信息
void welcome()
{
printf("+---------------------------+\n");
printf("| |\n");
printf("| 欢迎使用学生信息管理系统 |\n");
printf("| |\n");
printf("+---------------------------+\n");
}//系统主菜单
void mainmenu()
{
int choice;
choice = -1;
readData();
printf("\n温馨提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n");
do
{
printf("\n\n\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ 学生信息管理系统 |\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----录入学生信息 |\n");
printf("\t\t\t+ [2]----浏览学生信息 |\n");
printf("\t\t\t+ [3]----查询学生信息 |\n");
printf("\t\t\t+ [4]----删除学生信息 |\n");
printf("\t\t\t+ [5]----修改学生信息 |\n");
printf("\t\t\t+ [0]----退出系统 |\n");
printf("\t\t\t+*·*·*·*·*·*·*·*·*·*·|\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch(choice)
{
case 0:
writeData();
freeAll();
exit(0);
case 1:
record();
break;
case 2:
displayAll();
break;
case 3:
query();
break;
case 4:
del();
break;
case 5:
change();
break;
default:
printf("\n无效选项!");
break;
}
}
while(choice != 0);
}
//录入学生信息
void record()
{
struct student *p0;
p0 = (struct student *)malloc(LEN);
printf("请输入学生的学号:");
scanf("%ld",&p0->num);
printf("请输入学生的姓名:");
scanf("%s",p0->name);
printf("请输入学生的年龄:");
scanf("%d",&p0->age);
printf("请输入学生的性别:");
scanf("%s",p0->易做图);
printf("请输入学生的出生年月:");
scanf("%s",p0->birthday);
printf("请输入学生的地址:");
scanf("%s",p0->address);
printf("请输入学生的电话:");
scanf("%ld",&p0->tele_num);
printf("请输入学生的E-mail:");
scanf("%s",p0->E_mail);
insert(p0);
printf("该学生的信息为:\n");
printf("-------------------------------------------------------------------------------");
printf("学号\t姓名\t年龄\t性别\t出生年月\t\t地址\t电话\tE-mail\n");
display(p0);
}void insert(struct student *stu)
{
struct student *p0, *p1, *p2;
p1 = head;
p0 = stu;
if(head == NULL)
{
head = p0;
p0->next = NULL;
}
else
{
while((p0->num > p1->num)&&(p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(p0->num <= p1->num)
{
if(head == p1)
head = p0;
else
p2->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next = NULL;
}
}
TOTAL_NUM++;
}void display(struct student *p)
{
printf("%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n", p->num, p->name, p->age, p->易做图, p->birthday, p->address, p->tele_num, p->E_mail);
}