int count = 0;
struct Student {
char name[100];
int number;
struct Student* next;
};
struct Student* Creat()
{
struct Student* head = NULL;
struct Student* end, * new1;
end = new1 = (struct Student*)malloc(sizeof(struct Student));
printf("请输入姓名\n");
scanf("%s", &new1->name);
while (new1->name!=NULL)//为什么我输入为空,跳不出循环,怎么输入才能跳出循环啊
{
count++;
if (count == 1)
{
new1->next = head;
head = new1;
end = new1;
}
else
{
new1->next = NULL;
end->next = new1;
end = new1;
}
new1 = (struct Student*)malloc(sizeof(struct Student));
scanf("%s", &new1->name);
}
free(new1);
return head;
}
void print(struct Student* head)
{
struct Student* temp;
temp = head;
int n = 1;
printf("--有%d个成员:----\n", count);
printf("\n");
while (temp != NULL)
{
printf("NO:%d成员:\n", n);
printf("姓名:%s\n", temp->name);
printf("\n");
temp = temp->next;
n++;
}
}
int main()
{
struct Student* head;
head = Creat();
print(head);
return 0;
}
各位看看这个链表的循环怎么结束
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- 快乐鹦鹉 2023-03-29 21:00关注
new1->name!=NULL 永远不会是空啊
改为:
while(strlen(new1->name) == 0)
或者while(new1->name[0] != '\0')本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
- ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
- ¥15 CSAPPattacklab
- ¥15 一直显示正在等待HID—ISP
- ¥15 Python turtle 画图
- ¥15 关于大棚监测的pcb板设计
- ¥15 stm32开发clion时遇到的编译问题
- ¥15 lna设计 源简并电感型共源放大器
- ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
- ¥15 Vue3地图和异步函数使用