人生我靠演戏 2022-11-28 05:48 采纳率: 91.2%
浏览 7
已结题

对于链表输入的值无法输出,该如何解决。

img

img

img

以下为源码(我输入的数据它输出不了,找了很久不知道哪里错,各位看看怎么改)
 
#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;
}

展开全部

  • 写回答

2条回答 默认 最新

  • 时语-shine 2022-11-28 06:16
    关注
    while (new1->name != 0)
    

    好好想想你输入什么才能结束循环

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    人生我靠演戏 2022-11-28 08:21

    我找到了答案了

    回复
    人生我靠演戏 回复 人生我靠演戏 2022-11-28 08:21

    我看那么就原来循环错了。

    回复
查看更多回答(1条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 12月5日
  • 已采纳回答 11月28日
  • 创建了问题 11月28日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部