gpt4 book ai didi

c - 表达式语法错误

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

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct node
{
int data;
struct node *next;
}node;

node *create_cll(node *head,int n);

void main()
{
clrscr();
node *head,*p;
int n;
printf("Enter the no.of elements:");
scanf("%d",&n);
head=create_cll(*head,int n);
getch();
}

node *create_cll(node *head,int n)
{
node *rear,*p;
int i;
head=p;
for(i=1;i<n;i++)
{
p=(node*)malloc(sizeof(node));
scanf("%d",&p->data);
p=rear;
rear->next=p;
p=p->next;
}
printf("Circular linked list created..!");
return (head);
}

代码是关于创建循环链表的。但这里我有一个表达式语法错误,我无法解决。错误出现在 main() 部分的行中,其中 head 等于函数。所以我需要帮助...

最佳答案

你需要传递一个ptr-to-node,而不是一个节点;并删除 int关键字:

head = create_cll(head, n);

其他新闻:

  • 这是 int main在 C 中,不是 void main
  • 不要转换 malloc 的返回值在C中
  • 不测试 scanf 的返回值肯定会带来惊喜。
  • printf格式字符串通常有一个换行符 "\n"在最后。
  • <conio.h>getch不是 C(尽管盖茨先生希望你相信这一点。)使用 getchar()相反。

关于c - 表达式语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36522577/

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