以下为源码(我输入的数据它输出不了,找了很久不知道哪里错,各位看看怎么改)
#include <stdio.h>
#include <stdlib.h>
struct student {
char name[20];
int number;
struct student* next;
};
int count;
struct student* creat()
{
struct student* head = NULL;
struct student* end,*new1;
count = 0;
end = new1=(struct student*)malloc(sizeof(struct student));
printf("please input you need numbers:\n");
scanf("%s", &new1->name);
scanf("%d", &new1->number);
while (new1 ->name!=0)
{
count++;
if (count == 1)
{
new1->next = head;
end = new1;
head = new1;
}
else
{
new1->next = NULL;
end->next =new1;
end = new1;
}
new1 = (struct student*)malloc(sizeof(struct student));
scanf("%s", &new1->name);
scanf("%d",&new1->number);
}
free(new1);
return head;
}
void print(struct student* head)
{
struct student* temp;
int index = 1;
printf("有%d个成员\n",count);
temp = head;
while (temp != NULL)
{
printf("the NO%d menber is:\n", index);
printf("the name is:%s\n", temp->name);
printf("the number is:%d\n", temp->number);
printf("\n");
temp = temp->next;
index++;
}
}
int main()
{
struct student* head;
head = creat();
print(head);
return 0;
}
对于链表输入的值无法输出,该如何解决。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答
相关推荐 更多相似问题
点击登录
提问题
悬赏问题
- ¥20 OpenCV-Python简单轮廓寻找
- ¥20 使用matlab进行含参数的最优化求解及数值模拟
- ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
- ¥15 有Chang求三维杆单元几何非线性分析matlab代码
- ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
- ¥50 pyinstaller 打包问题
- ¥15 无法使用cnssc调取网页数据
- ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错
- ¥15 Python社区划分
- ¥15 游戏Aces.exe启动问题,想请教有没有友友可以看看如何解决~