-3

I'm making a basic connect five game and as much as I hate to admit it I'm having problems calling my functions. I'm not sure if I'm missing out any required information in the function calls or not but without calling them in main and just running them the program works as below but when I remove the commented out lines the output is just the line "Press any key to continue" and nothing comes up. Apologies for the menial question but I've been reading text book and the net and to my knowledge they should work. Any help would be much appreciated.

  #include <stdio.h>
#define   NONE           0
#define   PLYR_TOKEN     1
#define   COMP_TOKEN     6

int board[9][9];
int x, y;

void main()


//{
//  void get_coodinates();
//  void print_matrix();
//}

//void print_matrix()
    {

    int i, j, k=9, z=10;

    printf("\n");

        for(j = 0; j < k; ++j)
            {
                printf("\n  %d", --z);
                for(i = 0; i < k; ++i)

                    printf(" %d", board[x][y]);
            }
        printf("\n  | 1 2 3 4 5 6 7 8 9 \n");


//  }

//void get_coordinates()
    {
        do{
            printf("\n");
            printf("\n");
            printf("Input a column number then row number e.g. (1 4)   ");
            (scanf("%d %d", &x, &y));
            if (x < 1 || y <1 || x > 9 || y > 9)
                printf("\nERROR: Values must be between 1-9\n\n");
        else 
            printf("\n %s %d, %d. \n",
          "The position you input was", x, y);
        } while (x < 1 || y <1 || x > 9 || y > 9);
        if (board[x - 1][y - 1] != 0)
            {
            printf("Position taken enter new position\n");
            }
        else (board[x -1][y -1] = PLYR_TOKEN);

    }
}
user1745739
  • 11
  • 1
  • 2

2 Answers2

4

This:

void main()
{
   void get_coodinates();
   void print_matrix();
}

Should be changed to this:

int main()
{
   get_coodinates();
   print_matrix();

   ...
   return 0;
}

You do not need to include the return type when calling a function. In fact, doing so tells the compiler that you are declaring a function.

RA.
  • 7,542
  • 1
  • 34
  • 35
  • 1
    And `int main`, not `void main` – Seth Carnegie Oct 15 '12 at 00:24
  • Thank you for the prompt response. The two function calls now come up as errors with undeclared identifier. Should the functions be defined above the main for the compiler to recognise them or is this another error that exists in the way I've written the code? – user1745739 Oct 15 '12 at 00:28
  • @user1745739 You must place function prototypes above main in order for the compiler to recognize them. See http://en.wikipedia.org/wiki/Function_prototype – RA. Oct 15 '12 at 00:30
  • Thank you again. Adding the prototype functions has worked. In future I will try and do more focussed research before considering posting anything. – user1745739 Oct 15 '12 at 00:39
  • @user1745739 No problem. Have a look at the FAQ as well (http://stackoverflow.com/faq). – RA. Oct 15 '12 at 00:44
2
void main()    
{
  void get_coodinates();
  void print_matrix();
}

Those two lines in your main() function simply declare two functions. That is, you tell the compiler "There exists a function called get_coordinates. It takes no arguments, and returns nothing". Calling the functions looks like this:

void main()    
{
  get_coodinates();
  print_matrix();
}
Tom W
  • 1,304
  • 8
  • 9