Compiler error with pow() in a for loop
I'm a writing a function to print out a ternary tree in C. Of course, my method is terribly inefficient, but that's beside the point, all I need to do is print out the tree without regard to space or time complexity.
The compiler (gcc) is giving me an error on the line where the for loop is. I can't figure out what's wrong. I even set empty as a double, and I have included math.h, so I really do not see what the problem is. Please help! This is the output from the compiler: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
Regrettably, it's not being very specific about what the error actually is. I think there are 2 errors actually.
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));开发者_C百科 level++)
{
empty = checkLevel(node, level); // Print out any children that match the requested depth level and return the number of empty children
}
}
You've got an extra )
for(level = 2; empty != pow(3, level - 1)); level++)
^ here
精彩评论