views:

108

answers:

5

I have the following C code in a program:

printf("Test before print_foo()");
void print_foo(char board[ROW][COL]);
printf("Test after print_foo()");

where print_foo printf's the passed in 2-D character array with proper .c and .h files imported.

Console output is only the two printf statements. Debugging, the run-time never even steps into print_foo.

Any ideas?

+2  A: 
void print_foo(char board[ROW][COL]);

is not a function call. It's a declaration.

You probably want

print_foo(board);
Jurily
char needs to go too :)
JohnIdol
The "you probably want" line is probably incorrect. See Alex Martelli's answer for slightly more context and a more likely answer.
Don Wakefield
Whoops. char went too.
Jurily
+2  A: 

That looks like a function declaration to me - that's why your foo-nction is not being called.

JohnIdol
+2  A: 

Your middle line is just a function declaration, not a function call.

Don Wakefield
+3  A: 

That void prefix is making the middle line into a declaration of function print_foo (and the char within the parentheses means it would be invalid syntax otherwise). To just call print_foo, change the middle line to print_foo(board); (if board is how you named that 2-D character array).

Alex Martelli
+2  A: 

If you didn't declare the prototype previously then you have to write this :

printf("Test before print_foo()");
void print_foo(char board[ROW][COL]);
print_foo(board);
printf("Test after print_foo()");

In short you have to define/declare print_foo before invoking,or your compiler will flag an error !!

nthrgeek