人生我靠演戏 2022-11-28 13: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 14:16
    关注
    while (new1->name != 0)
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月6日
  • 已采纳回答 11月28日
  • 创建了问题 11月28日

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题