stu_t* listSearch(stu_t* head)//换成name就报错!
{
//int age ;
char temp[20]={0};
stu_t* p1 = NULL;
printf("输入要查询的学生姓名:");
//scanf_s("%d",&age);
scanf_s("%s",20,temp);
//while (age != 0)
while(temp != NULL)
{
if (head->next == NULL)
{
printf("没有此学生信息!");
return head;
}
p1 = head;
//while (age != p1->age && p1 -> next !=NULL)
while (temp != p1->name && p1 -> next !=NULL)
{
p1 = p1 ->next;
}
//if (age == p1 ->age)
if (temp == p1 ->name)
{
printf("%s %d",p1->name, p1->age);
free(p1);
}
else
//printf("查无%d学生信息!",age);
printf("查无%s学生信息!",temp);
free(p1);
printf("输入要查询的学生姓名:");
//scanf_s("%d",&age);
scanf_s("%s",temp);
}
return head;
}
这个是我定义的一个结构体指针函数,用来查找输入的信息,并输出查到的信息。但是,当输入信息之后,点击回车的时候,就开始报错,错误截图如下:
但是我把数组改成int型的变量(不是数组,注销部分)之后,就正常显示结果,但也会报错!截图如下:
求大神指点。谢谢!