bronya1465124479 2022-12-19 12:01 采纳率: 82.6%
浏览 93
已结题

按着课本的思路写的应该是没有错误但是为什么程序不能执行,希望有人能解答一下

问题遇到的现象和发生背景

按着课本的思路写的应该是没有错误但是为什么程序不能执行,希望有人能解答一下
程序目的是链表的构建和输出

遇到的现象和发生背景,请写出第一个错误信息
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
#include<stdio.h>
#include<stdlib.h>

struct node
{
    int ID,score;
    struct node *next;
    
};

int main()
{
    struct node *creat(struct node *head,int n);
    void print(struct node *head);
    
    struct node *head=NULL;
    int n;
    printf("please enter n length ");
    scanf("%d",&n);
    head=creat(head,n);
    print(head);
}

struct node *creat(struct node *head,int n)
{
    struct node *p,*q;
    int i;
    for(i=1;i<=n;i++){
      q=(struct node*)malloc(sizeof(struct node));
      printf("please enter the %dth ID score\n",i);
      scanf("%d %d",&q->ID,&q->score);
      q->next=NULL;
      if(head==NULL){
          head=q;
      }else{
          p->next=q;
      }
      p=q;
    }
    return head;
}

void print(struct node *head)
{
    struct node *p=head;
    while(p!=NULL){
        printf("ID:%d\nscore:%d\n",p->ID,p->score);
        p=p->next;
    }
}

运行结果及详细报错内容

img

img

img

我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”
  • 写回答

3条回答 默认 最新

  • qzjhjxj 2022-12-19 15:05
    关注

    题主上面的代码,没什么问题。

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

报告相同问题?

问题事件

  • 系统已结题 12月27日
  • 已采纳回答 12月19日
  • 修改了问题 12月19日
  • 修改了问题 12月19日
  • 展开全部

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c