Guest User

Untitled

a guest
May 21st, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. //Function prototypes
  6. void showBoard();
  7. void input(char *marker);
  8.  
  9. //Global
  10. char board[3][3] = {{'#','#','#'},{'#','#','#'},{'#','#','#'}};
  11.  
  12. int main(void)
  13. {
  14.     char marker;
  15.     char *ptrMarker = &marker;
  16.    
  17.     while (true)
  18.     {
  19.           showBoard();
  20.           input(ptrMarker);
  21.          
  22.     }
  23. }
  24.  
  25. void showBoard()
  26. {
  27.      printf(" 123\n");
  28.      for(int y = 0; y < 3; y++)
  29.      {
  30.              if(y > 0){ printf("\n"); }
  31.              printf("%d", y+1);
  32.              for(int x = 0; x < 3; x++)
  33.              {
  34.                     printf("%c", board[x][y]);
  35.              }
  36.      }
  37. }
  38.  
  39. void input(char *marker)
  40. {
  41.      if(  *marker == 'X')
  42.          *marker = 'O';
  43.      else
  44.          *marker = 'X';
  45.        
  46.        
  47.      char input[3];
  48.      
  49.      while( true )
  50.      {
  51.             printf("\n");
  52.             printf("%c", *marker);
  53.             scanf("%s", &input);
  54.            
  55.             if( isdigit(input[0]) && isdigit(input[1])) //Input form xy
  56.             {
  57.                 board[input[0]-1][input[1]-1] = *marker;
  58.                 break;
  59.             }
  60.             else if( isdigit(input[0]) && isdigit(input[2])) //Input form x,y or x:y, etc
  61.             {
  62.                 board[input[0]-1][input[2]-1] = *marker;
  63.                 break;
  64.             }
  65.      }
  66. }
Add Comment
Please, Sign In to add comment