c - 表达式语法错误

标签 c

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

相关文章:

c - 如何将输入从 read() 转换为 int

c - 子进程返回的函数是否可以在父进程中捕获

c - 在线程中使用共享内存

c - 有符号和无符号机器字类型

c++ - 为什么我应该在 c++ 而不是 c 中设置插件接口(interface)

c - 如何在这个 C printf 代码中换行?

c - 为什么我的 int 变量值突然跳跃?

C 套接字终止

c - 为什么 puts() 函数中的指针在以下代码的第 4 行中不起作用?虽然第 1 行正在运行

c# - 如何从 C# 调用带有 WCHAR* 参数的 C 函数?