Question
A word search is a game where letters of words are hidden in a grid (2D char array), that usually has a rectangular or square
A word search is a game where letters of words are hidden in a grid (2D char array), that usually has a rectangular or square shape. The objective of this game is to find and mark all the words hidden inside the grid. The words may be hidden horizontally (left-to-right ), vertically (top-to-bottom ) or diagonally (left-top-to-right-bottom ). Actually you solved this problem for the three cases in HW2.
Now you are asked to write a function that implements reverse horizontal (right-to-left <-- ) search to find out if a given word (a null terminated string) appears reverse horizontally in a given grid (2D array of characters, rows or columns are NOT null terminated). If the word appears reverse horizontally in the grid then your function should return 1 as well as the index values for the beginning row and column numbers (br, bc) of the hidden word in the grid; otherwise, the function returns 0.
Here is an example showing how the function that you will implement in the next page might be used in main( ).
/* suppose std C libs are included here */
#define ROW 2
#define COL 4
/* these numbers will be large in an actual program */
main() {
char g[ROW][COL] = {{'a','b','c','d'}, {'x','y','z','d'}};
char w[128];
int res, br, bc;
printf("Enter the word you want to search in the grid : ");
fgets(w, 127, stdin);
res = reverse_horizantal( g, w, &br, &bc);
/* YOU WILL IMPLEMENT */
if(res==1)
printf("Word %s appears reverse horizontally at (%d, %d) ", w, br, bc);
else
printf("Word %s is not found ", w);
}
/* For example when w is "dzy" the program should print dzy appears reverse horizontally at (1, 3) */
Hint: Suppose the function int substrindex(char *str, char *substr); that you implemented in Question 1 works correctly and available for you to use in this question. Recall that it returns -1 if substr is not in str; otherwise, it returns an index value showing where substr starts in str. This function expects both str and substr to be null terminated strings.
code:
int reverse_horizantal(char g[][COL], char *w, int *br, int *bc ) {
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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