Here I have a ttt code:
Code:
#include <stdio.h>
#include <windows.h>
int turn, move;
char name1[25], name2[25];
char board [9]; // The tic-tac-toe Board
void DrawBoard();
void DrawBoard() //* Draws the board *//
{
printf("\n\n");
printf(" %c | %c | %c \n", board[1], board[2], board[3]);
printf(" --------- \n");
printf(" %c | %c | %c \n", board[4], board[5], board[6]);
printf(" --------- \n");
printf(" %c | %c | %c \n", board[7], board[8], board[9]);
printf("\n\n");
}
void CheckSpace();
void CheckSpace() // Checks for double usage and places X's and O's
{
if (turn == 1)
{board[move] = 'X';}
else
{board[move] = 'O';}
}
int main()
{
BOOL StillPlaying=TRUE;
int move=0;
int turn=1;
printf("Welcome to tic-tac-toe!!!\n\n");
//players names
printf("What is player 1's name: ");
scanf("%s", name1);
printf("\nWhat is player 2's name: ");
scanf("%s", name2);
while (StillPlaying)
{
DrawBoard();
if (turn == 1){
printf("Please make a move %s : ", name1);
scanf("%d", &move);
turn=2;
printf("\n");
}
else{
printf("Please make a move %s : ", name2);
scanf("%d", &move);
turn=1;
printf("\n");
}
CheckSpace();
}//While Winner
return 0;
}// int main()
When I put the piece of code which assigns X's and O's in a function it seems to to see it or read it right. If I move the code in the while loop its okay.. Why is that