C++程序高手请帮忙分析一下
C程序高手请帮忙分析一下下面的代码,我需要每行有注释,我将给与高分,谢谢void readData()
{
FILE* fp;//文件指针
struct student *p1, *p2;
fp = fopen(FILE_DATA_PATH, "r");
if (!fp)
{
printf("文件打开错误!");
return;
}
fscanf(fp,"%d\n", &TOTAL_NUM);
head = p1 = p2 = (struct student *)malloc(LEN);
fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n",
&p1->num, p1->name, &p1->age, p1->易做图, p1->birthday, p1->address, &p1->tele_num, p1->E_mail);
while(!feof(fp))
{
p1 = (struct student *)malloc(LEN);
fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n",
&p1->num, p1->name, &p1->age, p1->易做图, p1->birthday, p1->address, &p1->tele_num, p1->E_mail);
p2->next = p1;
p2 = p1;
}
p2->next = NULL;
fclose(fp);
}
//删除学生信息
void del()
{
struct student *p1, *p2;
long int num;
if(head == NULL)
{
printf("无学生记录!\n");
return;
}
printf("请输入您要删除的学生的学号:");
scanf("%ld", &num);
p1 = head;
while(num != p1->num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(num == p1->num)
{
if(p1 == head)
head = p1->next;
else p2->next = p1->next;
free(p1);
TOTAL_NUM--;
}
else
printf("没有该学生记录,请核对!\n");
}
//修改学生信息
void change()
{
struct student *p1, *p2;
long int num;
if(head == NULL)
{
printf("无学生记录!\n");
return;
}
printf("请输入您要修改的学生的学号:");
scanf("%ld", &num);
p1 = head;
while(num != p1->num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(num == p1->num)
devise(p1);
else
printf("没有该学生记录,请核对!\n");
}
void devise(struct student *p)
{
int choice;
choice = -1;
do
{
printf("请选择您要修改的学生的信息内容:\n");
printf("+----------------------+\n");
printf("| 姓名 请按 1 |\n");
printf("| 年龄 请按 2 |\n");
printf("| 性别 请按 3 |\n");
printf("| 出生年月 请按 4 |\n");
printf("| 地址 请按 5 |\n");
printf("| 电话 请按 6 |\n");
printf("| E-mail 请按 7 |\n");
printf("| 取消 请按 0 |\n");
printf("+----------------------+\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch(choice)
{
case 0:
return;
case 1:
printf("请输入新姓名:");
scanf("%s", p->name);
break;
case 2:
printf("请输入新年龄:");
scanf("%d", &p->age);
break;
case 3:
printf("请输入新性别:");
scanf("%s", p->易做图);
break;
case 4:
printf("请输入新出生年月:");
scanf("%s", p->birthday);
break;
case 5:
printf("请输入新地址:");
scanf("%s", p->address);
break;
case 6:
printf("请输入新电话:");
scanf("%ld", &p->tele_num);
break;
case 7:
printf("请输入新E-mail:");
scanf("%s", p->E_mail);
break;
default:
printf("\n无效选项!");
break;
}
}while(choice != 0);
}
追问:#define FILE_DATA_PATH "student.txt"和while(!feof(fp))
{
p1 = (struct student *)malloc(LEN);
fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n",
&p1->num, p1->name, &p1->age, p1->易做图, p1->birthday, p1->address, &p1->tele_num, p1->E_mail);
p2->next = p1;
p2 = p1;
}
p2->next = NULL;
fclose(fp);
}
是什么意思啊?