user1695505
user1695505

Reputation: 265

Conflicting types when calling a method

#include <stdio.h>
#define MAX 9

void main (int argc, char *argv[]) {

  printBoard();

}

void printBoard(void) {
  int row,col;
  row=col=0;

  for(row;row<MAX;row++)   //row navigation
    for(col;col<MAX;col++){//column navigation
      printf("r:%d,c:%d",row,col);
    }/*End Column Nav*/

  printf("\n");
}

I'm not sure what I am doing wrong here - the error I get :

"warning: conflicting types for ‘printBoard’ [enabled by default] note: previous implicit declaration of ‘printBoard’ was here"

Upvotes: 1

Views: 334

Answers (3)

Morten Jensen
Morten Jensen

Reputation: 5936

You are calling the method before it is declared.

Solve the problem by:

1) Moving the definition of void printBoard(void) above main or

2) adding a declaration above main. Just this line: void printBoard(void);

Upvotes: 1

Jakub Baski Gabčo
Jakub Baski Gabčo

Reputation: 355

You have declared function after calling it.

#include <stdio.h>
#define MAX 9

void printBoard(void) {
  int row,col;
  row=col=0;

  for(row;row<MAX;row++)   //row navigation
    for(col;col<MAX;col++){//column navigation
      printf("r:%d,c:%d",row,col);
    }/*End Column Nav*/

  printf("\n");
}
void main (int argc, char *argv[]) {

  printBoard();

}

This should work pretty fine.

Edit: You should declar all function before calling any of them.
Like void printBoard(void);

Upvotes: 2

ben lemasurier
ben lemasurier

Reputation: 2592

Try adding a function prototype for printBoard above main() e.g.,

void printBoard(void);

void main(...)

Upvotes: 3

Related Questions