Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- //Function prototypes
- void showBoard();
- void input(char *marker);
- //Global
- char board[3][3] = {{'#','#','#'},{'#','#','#'},{'#','#','#'}};
- int main(void)
- {
- char marker;
- char *ptrMarker = ▮
- while (true)
- {
- showBoard();
- input(ptrMarker);
- }
- }
- void showBoard()
- {
- printf(" 123\n");
- for(int y = 0; y < 3; y++)
- {
- if(y > 0){ printf("\n"); }
- printf("%d", y+1);
- for(int x = 0; x < 3; x++)
- {
- printf("%c", board[x][y]);
- }
- }
- }
- void input(char *marker)
- {
- if( *marker == 'X')
- *marker = 'O';
- else
- *marker = 'X';
- char input[3];
- while( true )
- {
- printf("\n");
- printf("%c", *marker);
- scanf("%s", &input);
- if( isdigit(input[0]) && isdigit(input[1])) //Input form xy
- {
- board[input[0]-1][input[1]-1] = *marker;
- break;
- }
- else if( isdigit(input[0]) && isdigit(input[2])) //Input form x,y or x:y, etc
- {
- board[input[0]-1][input[2]-1] = *marker;
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment