student *luru() //从txt文件中读取全部学生信息
{
fflush(stdin); //清空缓冲区
char temp0[200];
FILE *fp;
printf("请输入毕业设计信息文本文档的地址(path) 示例:C:\\\\output\\\\毕业设计信息.txt\n");
while(1)
{
scanf("%s",temp0);
getchar();
fp=fopen(temp0,"r");
if(fp==NULL)
{
printf("地址错误,请重新输入正确的文本文档地址\n");
}
else
break;
}
student *p1,*p2,*head;
int n=0;
head=NULL;
p1=p2=(student *)malloc(sizeof(student));
while(fgets(temp0,160,fp)!=NULL)
{
n++;
char *temp;
temp=strtok(temp0,"\t"); ****************************************
strcpy(p1->num,temp);
temp=strtok(NULL,"\t");
strcpy(p1->cla,temp);
temp=strtok(NULL,"\t");
strcpy(p1->major,temp);
temp=strtok(NULL,"\t");
strcpy(p1->title,temp);
temp=strtok(NULL,"\t");
strcpy(p1->score,temp);
temp=strtok(NULL,"\t");
strcpy(p1->num1,temp);
temp=strtok(NULL,"\t");
strcpy(p1->na,temp);
temp=strtok(NULL,"\t");
strcpy(p1->clf,temp);
temp=strtok(NULL,"\t");
strcpy(p1->jud,temp);
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(student *)malloc(sizeof(student)); *******************************
}
p2->next=NULL;
Sleep(15000);
fclose(fp);
return head;
}
急需大神回答为什么在建立动态链表的过程中结构体指针p1中的数据在被赋值后会变化!!!