You will write a C program which reads in a 2D grid of characters which represen
ID: 644256 • Letter: Y
Question
You will write a C program which reads in a 2D grid of characters which represent a word-search similar to what you find in the newspaper Your program then prompts the user to enter words for which to search. A word can appear in any one of eight directions:
Reading strings from the user: use the get_string() function from simpleio.
I wrote a program that creates the cross word puzzle but can't get the user input to search the board in all eight ways. Any help would be appreciated. Also please only C language dont really know any other.
west-to-east
east-to-west
north-to-south
south-to-north
NW-to-SE
SE-to-NW
SW-to-NE
NE-to-SW
Explanation / Answer
int lookThroughPuzzle(const char puzzle[maxRows][maxCols], const char word[]){
int flag = 0; // inititalize flag to 0
int i, j;
for (i = 1; i < maxRows - 1; ++i){
for (j = 1; j < maxCols - 1; ++j){
if (lookAtLocation(puzzle, word, i, j, 1, 0)){
cout << word << " at " << i << ", " << j << " S" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, 0, 1)){
cout << word << " at " << i << ", " << j << " E" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, -1, 0)){
cout << word << " at " << i << ", " << j << " N" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, 0, -1)){
cout << word << " at " << i << ", " << j << " W" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, 1, -1)){
cout << word << " at " << i << ", " << j << " SW" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, -1, 1)){
cout << word << " at " << i << ", " << j << " NE" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, 1, 1)){
cout << word << " at " << i << ", " << j << " SE" << endl;
flag = 1;
}
if (lookAtLocation(puzzle, word, i, j, -1, -1)){
cout << word << " at " << i << ", " << j << " NW" << endl;
flag = 1;
}
}
}
if (flag == 1){
return 1;
}
else{
// flag is 0
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.