Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "functions.h"
  6.  
  7. int main()
  8. {
  9.     printf("Welcome to ""Tic-Tac-Toe""!\n-----------------------");
  10.    
  11.     char playerOne[32];
  12.     char playerTwo[32];
  13.    
  14.     printf("\nPlayer 1, state your name: ");
  15.     fgets(playerOne, sizeof playerOne, stdin);
  16.     strtok(playerOne, "\n");
  17.  
  18.     printf("\nPlayer 2, state your name: ");
  19.     fgets(playerTwo, sizeof playerTwo, stdin);
  20.     strtok(playerTwo, "\n");
  21.     printf("-----------------------");
  22.  
  23.     char startNumbers[3][3] = {
  24.         { '1', '2', '3' },
  25.         { '4', '5', '6' },
  26.         { '7', '8', '9' }
  27.     };
  28.  
  29.     int turn = 0;
  30.  
  31.     while (turn < 9)
  32.         {
  33.             printGame(startNumbers);
  34.             turn++;
  35.             int usedSquare = 0;
  36.  
  37.             if (turn % 2 == 1)
  38.             {
  39.                 printf("%s, in what square do you choose to put your X? ", playerOne);
  40.                 scanf("%d", &usedSquare);
  41.                 getchar();
  42.             }
  43.  
  44.             else
  45.             {
  46.                 printf("%s, in what square do you choose to put your O? ", playerTwo);
  47.                 scanf("%d", &usedSquare);
  48.                 getchar();
  49.             }
  50.  
  51.             if (usedSquare > 9)
  52.             {
  53.                 printf("That square does not exist! Try again...\n");
  54.                 turn--;
  55.             }
  56.         }
  57.    
  58.  
  59.     getchar();
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement