I need help in this question in C program. Consider a 2D array of strings based on the following declarations/definitions: #define ROWSIZE 4 #define COLSIZE 3 typedef char Str30[31]; Str30 Words[ROWSIZE][COLSIZE]; // 2D array of string An example Words[ ][ ] array is shown below.
I need help in this question in C program.
Consider a 2D array of strings based on the following declarations/definitions:
#define ROWSIZE 4
#define COLSIZE 3
typedef char Str30[31];
Str30 Words[ROWSIZE][COLSIZE]; // 2D array of string
An example Words[ ][ ] array is shown below.
col0 | col1 | col2 | |
row0 | dOg | Neko | Cat |
row1 | Hello | gOoDbYE | WELCOME |
row2 | GREEN | CauliFlower | Blue |
row3 | Code | Programmer | SynTaX |
: Implement the function void Search(Str30 key, Str30 Words[][COLSIZE], Str30 result, int *pRowIndex, *pColIndex) where key is the word that we are searching if it is has a match in Words[ ][ ] array.
Coding format -
void Search(Str30 Words[][COLSIZE], Str30 key, Str30 result, int *ptrRowIndex, int *ptrColIndex)
{
// write code here
}
If the key is found, the result parameter is set such that the first character is a + concatenated with the matching word copied verbatim followed by one more +. The values of *pRowIndex and *pColIndex should be set to contain the row index and column index where the key was found in Words[ ][ ] array.If key is not found, the result parameter is set such that the first character is a – followed by the key (copied verbatim) followed by one more –. The values of *pRowIndex and *pColIndex should be set to contain -1 to indicate that the key was not found.
Just like Google search, the Search() function is NOT case sensitive. This means that it does not distinguish between lower and upper case.
For example, the strings “DOG”, “dog”, “Dog”, and “doG” are all considered as the same word.
Example: The following are sample calls and expected output printed via printf(). Assume that variables row and cow were declared as integer variables.
Search(“programmer”, Words, result, &row, &col);
printf(“%s %d %d\n”, result, row, col); prints +prOgraMmeR+ 3 1
Search(“green”, Words, result, &row, &col);
printf(“%s %d %d\n”, result, row, col); prints +GREEN+ 2 0
Search(”GoodNight”, Words, result, &row, &col);
printf(“%s %d %d\n”, result, row, col); prints -GoodNight- -1 -1
Step by step
Solved in 3 steps with 2 images