How to write a tic tac toe game program in c language using int char array with the help of for & while loop

Recommended Answers

All 3 Replies

Please show us what you have so far.

How to write a tic tac toe game program in c language using int char array with the help of for & while loop

Using your knowledge of the C Language and a C compiler. Why do you ask? Oh, forgive me. You didn't ask. You simply made a statement. Nevermind.

Please show us what you have so far.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>


#define u ' '

char game[3][3]={/*the tic-tac-toe game*/
u, u, u,
u, u, u,
u, u, u};

void Khan(void), 1(void);
void disp(void);
int chk(void);

main()
{
char game;
int counter=0;
printf("This is the game of Tic-Tac-Toe.\n");
printf("You will be playing against your partner.\n");
game= u;
do{
app();
Baloch();
game=chk();
app();
Khan();
game=chk();
app();
if(game!= u) break;
Baloch();
game=chk();

Khan();
game=chk();

}while((game== u)&& (counter<9));
if(game=='X')printf("a man won!\n");
else printf("b man won!!!!\n");
b++ ;

app();
getch();
return 0;
}


void Baloch(void)
{
int x,y;

printf("Enter coordinates for your X: ");
scanf("%d%d",&x,&y);
x--;y--;
if(game[x][y]!= u){
printf("Invalid move,try again.\n");
Baloch();
}
else game[x][y]='X';
}


void Khan(void)
{
int x,y;

printf("Enter coordinates for your o: ");
scanf("%d%d",&x,&y);
x--;y--;
if(game[x][y]!= u){
printf("what the F**k u are entering :( .\n");
user2();
}
else game[x][y]='O';
}


void disp(void)
{
int r;

for(r=0;r<3;r++){
printf(" %c | %c | %c ", game[r][0],
game[r][1], game[r][2]);
if(r!=2) printf("\n---|---|---\n");
}
printf("\n");
}


char input1='x';
char input2='o';


check(input1);


check(input2)

int check(input) void

for(row=0;row<3;row++)

{
(ttt[row][1]==input) &&(ttt[row][2]==input)&&(ttt[row][0]==input)
printf("you won");
}
for(col=0;col<3;col++)

{
if(ttt[1][col]==input) &&(ttt[2][col]==input)&&(ttt[0][col])
printf("you won");
}
if
if(ttt[0][0]==ttt[1][1] && ttt[1][1]==ttt[2][2])
return game[0][0];
if(ttt[0][2]==ttt[1][1] && ttt[1][1]==ttt[2][0])
return ttt[0][2];


}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.