Question: Using C Programming Only! Comment as much as you can please! Write a function win() with the following prototype: int win(char board[6][6], char player) The

Using C Programming Only! Comment as much as you can please!

Write a function win() with the following prototype:

int win(char board[6][6], char player)

The function win should return a 1 if the character player is found in three consecutive positions in the board.

Consecutive for this lab means in the same row, or in the same column, NOT on a diagonal.

For the board shown below,

A B B D E G Z A B G G E Z B A G G G Z Z X G K K X X O K O W X X O O W W 

The following values should be returned by win() if called as:

win(board,'A') would return 0

win(board,'B') would return 0

win(board,'D') would return 0

win(board,'G') would return 1

win(board,'O') would return 0

win(board,'X') would return 0

win(board,'Z') would return 1

#include #include

int win(char board[6][6], char player) { // insert your code for the function here return -1; }

int main() {

//initialize the array

char board[6][6]; int i,j; char user; int gameresult;

//read in the board printf("Enter 36 values for the 6x6 game board "); for(i=0;i<6;i++){ for(j=0;j<6;j++) { scanf("%c ",&(board[i][j])); } } // print the board for(i=0;i<6;i++){ for(j=0;j<6;j++) { printf("%c ",(board[i][j])); } printf(" "); }

printf("Enter the uesr's token to see if they won the game!"); scanf("%c",&user); printf(" ");

gameresult = win(board,user);

if (gameresult == 1) printf("Player %c won the game!",user); else if (gameresult == 0) printf("Player %c didn't win.",user); else printf("invalid response from win() ");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!