/* Peter Cline -- July 18 2007
   Writing a game of Tic Tac Toe

	MODIFIED BY:
	(name)
	(date)

	FILL THAT PART IN!
*/

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

void blankTable(char tttTable[3][3]);
void printTable(char tttTable[3][3]);

int main() {
  char ttt[3][3];
  int row, col;
  char currentPlayer = 'X';

  blankTable(ttt);
  printTable(ttt);

  printf("\nPlayer %c, enter a row and a column: ", currentPlayer);
  scanf("%d%d", &row, &col);
  while (row != -1 && col != -1) {

    //update table
    ttt[row][col] = currentPlayer;
    printTable(ttt);

    // change current player
    if (currentPlayer == 'X')
      currentPlayer = 'O';
    else
      currentPlayer = 'X';

    printf("\nPlayer %c, enter a row and a column: ", currentPlayer);
    scanf("%d%d", &row, &col);
  }

  return 0;
}

// initializes tttTable with the character '-' in every array element
void blankTable(char tttTable[3][3]) {
  int i;
  int j;

  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      tttTable[i][j] = '-';
    }
  }
}

// nicely print the contents of the board
void printTable(char tttTable[3][3]) {
  int i;
  int j;

  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      printf(" %c ", tttTable[i][j]);
    }
    printf("\n");
  }
}


