Purpose: Use of two dimensional CHARACTER arrays and for loops Passing arrays between functions Description Implement a C program using functions and arrays. Ask user
Purpose:
Use of two dimensional CHARACTER arrays and for loops
Passing arrays between functions
Description
Implement a C program using functions and arrays. Ask user for a row / column for a tic/tac/toe game. Check if the row/column is valid using checkError( int, int ). This function takes two integers as input argument and returns an integer. It returns 1 if the row/column is valid otherwise it will return a 0. Use a loop to continue to ask for an input until the user enters a good row/column. Prototype: int checkError(int, int, char [ ] [ ]);
setGame this function will take the two dimensional character array and put a - in every location to set up the game. Prototype: void setGame(char [ ] [ ]);
Next function to implement is:
printGame Takes in a two dimensional array that represents the tic tac toe game board. Displays the current game board state as shown in the sample output below.
Prototype: void printGame(char [ ] [ ]);
Make sure you pay attention to prototypes, function calls and function definitions. Not writing in the form of function prototypes will result in loss of credit in the labs. You will use functions like these in the lab next week.
Check the Sample output before you start.
Sample Output
Characters in bold are input from the user
$ ./a.out
Welcome to the game!
1 2 3
1 - - -
2 - - -
3 - - -
Enter a row and column to place your X in (0 0 to quit): 1 2
1 2 3
1 - X -
2 - - -
3 - - -
Enter a row and column to place your O in (0 0 to quit): 1 2
Sorry, that spot is not valid. Try again: 3 1
1 2 3
1 - X -
2 - - -
3 O - -
Enter a row and column to place your X in (0 0 to quit): 3 3
1 2 3
1 - X -
2 - - -
3 O - X
Enter a row and column to place your O in (0 0 to quit): 2 2
1 2 3
1 - X -
2 - O -
3 O - X
Enter a row and column to place your X in (0 0 to quit): 3 4
Sorry, that spot is not valid. Try again: 3 1
Sorry, that spot is not valid. Try again: 1 3
1 2 3
1 - X X
2 - O -
3 O - X
Enter a row and column to place your X in (0 0 to quit): 0 0
Game over!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started