Tic-Tack-Toe problem

I had to create a program for my c programming class for a tic-tack-toe board. the program worked just fine until I found out part of it was suppose to be a function. I took part of it out for a function, but it keeps saying "invalid types'int[int]' as a subscript" and "cannot convert 'int[*][3]' to 'int*' for argument '1' to 'void win(int*,int*)'. I don't understand why it is showing this. I will put the program and the function here.

int main(void)
{
int ct1=0, ct2=0, pct=0, ttt[3][3]={0}, r, c, thin=0, player=1, wchoice=0, game=1, choice, gcnt=0, tie=0;
//Starts by asking the user to play. Keeps looping. Checks to see if the input is valid
while(game!=2)
{
printf("Enter 1 to play, 2 to quit");
scanf("%d",&game);
if(game==2)
{
system("pause");
return 0;
}
if(game==1)
game=1;
else
{
game=2;
printf("Please choose a correct option\n");
}
//Prints out the Board

while(thin==0&&tie==0&&game!=2)
{
printf("\n\n\n\n\n");
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
printf("%d ",ttt[r][c]);
}
printf("\n");
}

//Prints out the player and askes them to choose a square
printf("\nPlayer %d. ",player);
fflush(stdin);
printf("Enter the number that corresponds with the square");
printf("(Top left is 1, top middle is 2, ect., middle left is four):");
scanf("%d",&choice);
//Checks to see if the square is filled and fills it with the player number
switch(choice)
{
case 1:
if(ttt[0][0]==0)
ttt[0][0]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 2:
if(ttt[0][1]==0)
ttt[0][1]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 3:
if(ttt[0][2]==0)
ttt[0][2]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 4:
if(ttt[1][0]==0)
ttt[1][0]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 5:
if(ttt[1][1]==0)
ttt[1][1]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 6:
if(ttt[1][2]==0)
ttt[1][2]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 7:
if(ttt[2][0]==0)
ttt[2][0]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 8:
if(ttt[2][1]==0)
ttt[2][1]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
case 9:
if(ttt[2][2]==0)
ttt[2][2]=player;
else
{
printf("\nPlease choose another square\n\n");
wchoice=1;
}
break;
default:
printf("\nPlease Enter the options listed\n");
wchoice=1;
break;
//Checks to see if you have three-in-a-row
}
win(ttt,&thin);
//Switches the player if the conditions are right(no wrong entry)
if(player==1&&wchoice==0&&pct!=1&&thin!=1)
{
player=2;
pct=1;
}
if(player==2&&wchoice==0&&pct!=1&&thin!=1)
{
player=1;
pct=1;
}
//Checks to see if every square is filled for a tie
if(wchoice!=1)
gcnt++;
wchoice=0;
pct=0;
fflush(stdin);
if(gcnt==9)
tie=1;
}
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
ttt[r][c]=0;
}
}
//Checks if there-is-three-in-a-row, adds 1 to the wins, and prints your win
if(thin==1||tie==1)
{
if(player==1&&thin==1)
ct1++;
if(player==2&&thin==1)
ct2++;
if(thin==1)
printf("Tic-Tac-Toe! Player %d won!\n",player);
//Prints if you made a tie
if(tie==1)
{
printf("It was a tie\n");
}
//Prints Each player's number of wins, then runs the program again
if(game!=2)
printf("Wins: Player 1-%d Player2-%d\n",ct1,ct2);
thin=0;
tie=0;
gcnt=0;

}
game=1;
}
system("pause");
return 0;
}


void win(int ttt[], int *thin)
{
if(ttt[0][0]==1&&ttt[0][1]==1&&ttt[0][2]==1)
*thin=1;
if(ttt[0][0]==1&&ttt[1][0]==1&&ttt[2][0]==1)
*thin=1;
if(ttt[0][0]==1&&ttt[1][1]==1&&ttt[2][2]==1)
*thin=1;
if(ttt[0][1]==1&&ttt[1][1]==1&&ttt[2][1]==1)
*thin=1;
if(ttt[0][2]==1&&ttt[1][2]==1&&ttt[2][2]==1)
*thin=1;
if(ttt[0][2]==1&&ttt[1][1]==1&&ttt[2][0]==1)
*thin=1;
if(ttt[1][0]==1&&ttt[1][1]==1&&ttt[1][2]==1)
*thin=1;
if(ttt[2][0]==1&&ttt[2][1]==1&&ttt[2][2]==1)
*thin=1;
if(ttt[0][0]==2&&ttt[0][1]==2&&ttt[0][2]==2)
*thin=1;
if(ttt[0][0]==2&&ttt[1][0]==2&&ttt[2][0]==2)
*thin=1;
if(ttt[0][0]==2&&ttt[1][1]==2&&ttt[2][2]==2)
*thin=1;
if(ttt[0][1]==2&&ttt[1][1]==2&&ttt[2][1]==2)
*thin=1;
if(ttt[0][2]==2&&ttt[1][2]==2&&ttt[2][2]==2)
*thin=1;
if(ttt[0][2]==2&&ttt[1][1]==2&&ttt[2][0]==2)
*thin=1;
if(ttt[1][0]==2&&ttt[1][1]==2&&ttt[1][2]==2)
*thin=1;
if(ttt[2][0]==2&&ttt[2][1]==2&&ttt[2][2]==2)
*thin=1;
}
closed account (oN3AqMoL)
When declaring ttt, you may never declare it with regular ints or simply by saying: {0}. Fix that and reply if it still doesnt work.

1
2
3
//Correct Declaration:
int x,y,z;
int xArray[3][3][3];
Last edited on
Thank you. I was able to get my program working
closed account (oN3AqMoL)
By the way, use the bar on the format. It looks like this: <>.

This makes your code MUCH easier to read.
Topic archived. No new replies allowed.