一个函数不能完成工作,哪里有问题?求指点~
程序代码:
void input(Link point) //输入信息
{
Link p1,p2,p3;
int flag=0;
char decision[5],student_ID[20];
p2=point;
p3=point;
display(point);
while(p2->next!=NULL)
p2=p2->next;
while(1)
{
while(1)
{
puts("Please input student_ID.(Press \"quit\" to quit.)");
gets(student_ID);
if(strcmp(student_ID,"quit")==0)
{
puts("********************Press Enter key to quit!********************");
getchar();
return;
}
while(p3->next!=NULL)
{
if(strcmp(p3->data.student_ID,student_ID)==0)
{
puts("********************student_ID already exists!********************");
flag=1;
puts("********************Press Enter key to continue.********************");
getchar();
break;
}
p3=p3->next;
}
if(flag==1)
{
puts("Do you want to re-enter it?");
gets(decision);
if(strcmp(decision,"yes")==0)
continue;
else
return;
}
else
break;
}
p1=(Link)malloc(sizeof(Node));
if(p1==NULL)
{
puts("********************Memory space application failed!********************");
puts("********************Type the Enter key to return to the menu.********************");
getchar();
return;
}
strcpy(p1->data.student_ID,student_ID);
puts("Please input student's name.(Only 10 letters are allowed.)");
scanf("%s",p1->data.name);
p1->data.English_grade=input_score("Please input the English score.");
p1->data.Math_grade=input_score("Please input the Math score.");
p1->data.C_grade=input_score("Please input the C score.");
p1->data.total_points=p1->data.English_grade+p1->data.Math_grade+p1->data.C_grade;
p1->data.average_score=(float)(p1->data.total_points/3);
p1->data.ranking=0;
p1->next=NULL;
p2->next=p1;
p2=p1;
fflush(stdin);
}
save(point);
puts("********************Type the Enter key to return to the menu.********************");
getchar();
}
void save(Link point) //保存记录
{
FILE *fp;
Link pt;
int count=0;
fp=fopen(file,"wb");
if(fp==NULL)
{
puts("****************Sorry,file open failed!*****************");
puts("*******************Press Enter key to return.*****************");
getchar();
return;
}
pt=point;
while(pt);
{
if(fwrite(pt,sizeof(Node),1,fp)==1)
{
pt=pt->next;
count++;
}
}
if(count>0)
{
puts("\n\n\n*************Save success!*************");
printf("A total of %d records were saved.\n",count);
puts("*****************Press Enter key to continue.******************");
getchar();
}
else
{
puts("***********************No records can be saved!**********************");
puts("************************Press Enter key to continue.************************");
getchar();
}
fclose(fp);
}
我写的函数应该能够判断studentID是否重复的,但结果却没有给出判断,并且没有保存数据。
求大侠指点哪个地方错了。。。。。
[此贴子已经被作者于2016-1-24 21:19编辑过]






