for 循环中 pow() 的编译器错误

标签 c casting for-loop double

我正在用 C 语言编写一个函数来打印出一棵三元树。当然,我的方法效率非常低,但这不是重点,我需要做的就是打印出树而不考虑空间或时间复杂性。

编译器 (gcc) 在 for 循环所在的行上给我一个错误。我不知道出了什么问题。我什至将 empty 设置为 double,并且包含了 math.h,所以我真的看不出问题是什么。请帮忙!

这是编译器的输出:

make traverse clean gcc -c -Wall traversals.c
traversals.c: In function ‘printTree’:
traversals.c:112: error: syntax error before ‘)’ token
traversals.c:112: error: syntax error before ‘)’ token
make: * [traversals.o] Error 1

遗憾的是,它并没有非常具体地说明错误到底是什么。我认为实际上有 2 个错误。

void printTree(node_t* node)
{
    printf("%d %s %d\n", node->depth, node->string, node->counter); // Print the root node
    int level;
    double empty = 0;
    // Starting from the second level and ending when all the children of a particular level are null
    for(level = 2; empty != pow(3, level - 1)); level++)
    {
        empty = checkLevel(node, level); // Print out any children that match the requested depth level and return the number of empty children
    }
}

最佳答案

你有一个额外的)

for(level = 2; empty != pow(3, level - 1)); level++)
                                         ^ here

关于for 循环中 pow() 的编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7533726/

相关文章:

c - 在 C 中的循环中重新声明 VLA 数组

c - 指向结构体和类型转换的指针

python - 如何打破 Python 中的嵌套 for 循环?

python - 在预定义的位置将一个列表中的值插入到另一个列表中

c++ - 如何更改 code::blocks 中的文本颜色和控制台颜色?

C指针总是包含它自己的内存地址?

c - ISO C++ 禁止比较指针和整数 : File handling in C error

ios - 从 'const b2Shape*' 到 'b2PolygonShape*' 的动态转换会放弃限定符吗?

pointers - 如果 D 包含类型 B 的对象作为其第一个成员,则在 B* 和 D* 之间进行转换是否安全?

java - 为什么它会跳过数组索引 0?