gpt4 book ai didi

如果可以的话,完成此代码 (c)

转载 作者:行者123 更新时间:2023-11-30 21:44:38 24 4
gpt4 key购买 nike

#include<stdlib.h>
typedef struct node
{
int data;
int help;
struct node* next;
}Node;
void Nodes_maker(int nums,Node *currentnode);
int main()
{
int count2;
Node* root;
Node* currentnode;
currentnode=root;
printf("How many numbers do you want? ");
scanf("%d",&count2);
Nodes_maker(count2,&currentnode);
return 0;
}
void Nodes_maker(int nums,Node *currentnode)
{
int i;
for(i=0;i<nums;i++)
{
currentnode->next=(Node*)malloc(sizeof(Node));
}
}

有人能帮我完成这段代码吗?我有包含“数据”、“帮助”、“下一个”的节点结构。我想从用户那里扫描一个数字,了解他想要多少个数字(他想要多少个“数据”字段)并制作这些节点结构(“下一个”字段包含指向另一个节点结构中另一个新“数据”字段的指针) .

最佳答案

更改此:

Nodes_maker(count2,&currentnode);

对此:

Nodes_maker(count2, currentnode);

错误就会消失。这是因为该函数的原型(prototype)是 Nodes_maker(int nums,Node *currentnode) 并且您有 Node* currentnode;

但是,你需要加强你的逻辑。我的意思是您动态分配内存,但不返回指针(您的函数返回void)。祝你好运!

<小时/>

PS:Do I cast the result of malloc?没有。

关于如果可以的话,完成此代码 (c),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44502297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com