#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/