【问题标题】:error: expected expression before ',' token错误:“,”标记之前的预期表达式
【发布时间】:2016-04-21 18:35:54
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

    struct nodes
    {
        char* info;
        struct nodes * left;
        struct nodes * right;

    };

    char* question = "any question?";
    struct nodes * node = NULL;
    struct nodes * nodeleft = NULL;
    struct nodes * noderight = NULL;

    struct nodes newNode (char info[50], struct nodes * l, struct nodes * r)        `       {
        struct nodes conf;
        conf.info = info;
        conf.left = l;
        conf.right = r;
        return conf;
    }

我在这里尝试创建一个左右节点为空的新根节点

    int main(){
        node = newNode (question, nodoleft*, nodoright*);

        return 0;
    }

不知道为什么我在尝试创建新节点时遇到此错误...我是 C 新手 错误:错误:“,”标记之前的预期表达式

【问题讨论】:

  • nodoleft*, nodoright*);...hmmmmm
  • 对不起是 nodeleft*, noderight* 但它一直收到同样的错误
  • 在 main 中,节点的类型为 struct nodes*,但 newNode 返回 struct nodes
  • @JohanOZ : nodo 不是唯一的问题,* 后缀也不正确。
  • node = newNode (question, nodeleft, noderight); 怎么样?

标签: c


【解决方案1】:

"nodoleft*,""nodoright*" 中,您看起来好像开始了乘法运算,然后没有第二个操作数就停止了。在任何情况下,每个参数都应该是一个表达式。在这种情况下,变量名确实有资格作为表达式。所以,如果你有

node = newNode (question, nodeleft, noderight);

你的编译器可能会更快乐。

【讨论】:

  • 它没有解决没有为节点分配永久存储的事实。
  • @stark 真的。我的意图只是解决 OP 的问题。
猜你喜欢
  • 2014-02-22
  • 2015-03-28
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 2017-09-24
  • 2012-03-09
相关资源
最近更新 更多