Hey there, i'm new to this forum and i am in need of a little help.
As part of a C programming assignment i have been asked to design a tic-tac-toe program using a 7x7 array and pointers.
I have just about got my head around the pointers but i am having problems creating a function to take co-ordinate values from the user and inputting them as either an 'X' or 'O'.
Here is my code so far.
Code:
#include <stdio.h>
#define I 7
#define J 7
#define player1 88
#define player2 79
printboard(int (*board)[7]);
mainmenu();
TwoPlayer();
OnePlayer();
void main()
{
int select;
select=mainmenu();
switch(select)
{
case 1 : printf("You selected 2 player mode\n\n");
TwoPlayer();
break;
case 2 : printf("You selected 1 player mode\n\n");
break;
case 3 : printf("\n\n");
exit(0);
break;
}
//printboard(board);
}
TwoPlayer()
{
int board[I][J];
int i, j, select;
int x,y;
for (i=0; i<7; i++) // clear board
for (j=0; j<7; j++)
board[i][j]='\0';
x=1;
y=1;
//FirstPlayer();
board[1][2]=player1;
board[x][y]=player2;
printboard(board);
}
mainmenu()
{
int select;
printf("*****************************************************\n");
printf(" Please select wich game mode you would like to play \n");
printf(" 1 - Two player 2 - One Player \n");
printf(" 3 - Quit \n");
printf("*****************************************************\n");
scanf("%d",&select);
return(select);
}
printboard(int (*board)[7])
{
int i, j;
printf(" |");
for (j=0; j<J; j++)
{
printf(" %d |",j);
}
printf("\n");
for (i=0; i<I; i++)
{
printf("------------------------------\n");
printf("%d",i);
printf("|");
for (j=0; j<J; j++)
{
//printf(" %c |",board[i][j]);
printf(" %c |",*(*(board+i)+j));
}
printf("\n");
}
printf("------------------------------\n");
}
Any advice on where to go next would be greatly appreciated.
Greg