In C language Write a program that finds the strings in the
In C language!!!
Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these strings to another array of strings named words[18][11]. Then use a nested loop to print the crossword puzzle itself. Then use words[18][11]and a loop to print a list of all 18 words in the puzzle.
Output:
Hello! You were expecting the answer here?
Please print the puzzle itself in puzzle format.
Followed by each word in the puzzle, formatted as a list.
Use the following code/psuedocode:
char crossword[20][20] = {
    \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \'G\', \' \', \'R\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \',
    \' \', \'P\', \'R\', \'O\', \'V\', \'O\', \'L\', \'O\', \'N\', \'E\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \'C\', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \'U\', \' \', \'M\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \'A\', \' \', \' \',
    \' \', \'S\', \' \', \' \', \' \', \'D\', \' \', \'A\', \' \', \' \', \' \', \' \', \'B\', \' \', \' \', \'F\', \' \', \'M\', \' \', \' \',
    \' \', \'W\', \' \', \' \', \' \', \'A\', \' \', \'N\', \' \', \' \', \' \', \'G\', \'R\', \'U\', \'Y\', \'E\', \'R\', \'E\', \' \', \' \',
    \' \', \'I\', \' \', \' \', \' \', \' \', \' \', \'O\', \' \', \' \', \' \', \' \', \'I\', \' \', \' \', \'T\', \' \', \'M\', \' \', \' \',
    \' \', \'S\', \' \', \'M\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \'E\', \' \', \' \', \'A\', \' \', \'B\', \' \', \' \',
    \' \', \'S\', \' \', \'U\', \' \', \' \', \' \', \' \', \' \', \' \', \'C\', \' \', \' \', \' \', \' \', \' \', \' \', \'E\', \' \', \' \',
    \' \', \' \', \' \', \'E\', \' \', \' \', \'M\', \' \', \' \', \' \', \'A\', \' \', \' \', \' \', \' \', \'R\', \' \', \'R\', \' \', \' \',
    \' \', \' \', \' \', \'N\', \' \', \' \', \'O\', \' \', \' \', \' \', \'M\', \' \', \'R\', \'I\', \'C\', \'O\', \'T\', \'T\', \'A\', \' \',
    \' \', \' \', \' \', \'S\', \' \', \' \', \'Z\', \' \', \' \', \' \', \'E\', \' \', \' \', \' \', \' \', \'Q\', \' \', \' \', \' \', \' \',
    \' \', \' \', \' \', \'T\', \' \', \' \', \'Z\', \' \', \' \', \' \', \'M\', \' \', \' \', \' \', \' \', \'U\', \' \', \' \', \' \', \' \',
    \' \', \'C\', \'H\', \'E\', \'D\', \'D\', \'A\', \'R\', \' \', \' \', \'B\', \' \', \' \', \' \', \' \', \'E\', \' \', \' \', \' \', \' \',
    \' \', \' \', \' \', \'R\', \' \', \' \', \'R\', \' \', \' \', \' \', \'E\', \' \', \'G\', \' \', \' \', \'F\', \' \', \'J\', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \' \', \'E\', \' \', \'G\', \'O\', \'R\', \'G\', \'O\', \'N\', \'Z\', \'O\', \'L\', \'A\', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \' \', \'L\', \' \', \' \', \' \', \'T\', \' \', \'U\', \' \', \' \', \'R\', \' \', \'C\', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \' \', \'L\', \' \', \' \', \' \', \' \', \' \', \'D\', \' \', \' \', \'T\', \' \', \'K\', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \'P\', \'A\', \'R\', \'M\', \'I\', \'G\', \'I\', \'A\', \'N\', \' \', \' \', \' \', \' \', \' \', \' \',
    \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \'
 };
 char words[18][11];
 /*
 Here is an algorithm to find words in puzzle array
 and copy them to words array.
Look at every char in puzzle. If it is not a space,
 then check if it is the start of a word.
Verticle words have spaces left, right, and above.
 Horizontal words have spaces top, bottom, and left.
Every word ends with a space.
 */
 // look at every char in puzzle
 for each row
 {
    for each col
    {
    // is crossword[row][col] not a space?
    {
        // is it the start of a vert word?
        // space above && space left && space right
        {
            // copy it to words
            for each j until crossword[row + j][col] is a space)
            {
                // copy each char to wordrow, (vertically)
                words[wordrow][j] = crossword[row + j][col];
            }
            words[wordrow][j] = 0; // insert null terminator
            //increment word row index
        }
        // is it the start of a horz word?
        // if(space above && space left && space below)
        {
            // copy it to words
            for each j until crossword[row][col + j] is a space
            {
            // copy each char to wordrow, (horizontally)
            words[wordrow][j] = crossword[row][col + j];
        }
            words[wordrow][j] = 0; // insert null terminator
            // increment word row index
        }
    } // end if not space code block
} // end col loop
 } // end row loop
 // print words array
 // another loop here, cycle thru words[j]
Solution
#include <stdio.h>
int main()
 {
 char crossword[20][20] = {
 \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \'G\', \' \', \'R\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \',
 \' \', \'P\', \'R\', \'O\', \'V\', \'O\', \'L\', \'O\', \'N\', \'E\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \'C\', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \'U\', \' \', \'M\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \'A\', \' \', \' \',
 \' \', \'S\', \' \', \' \', \' \', \'D\', \' \', \'A\', \' \', \' \', \' \', \' \', \'B\', \' \', \' \', \'F\', \' \', \'M\', \' \', \' \',
 \' \', \'W\', \' \', \' \', \' \', \'A\', \' \', \'N\', \' \', \' \', \' \', \'G\', \'R\', \'U\', \'Y\', \'E\', \'R\', \'E\', \' \', \' \',
 \' \', \'I\', \' \', \' \', \' \', \' \', \' \', \'O\', \' \', \' \', \' \', \' \', \'I\', \' \', \' \', \'T\', \' \', \'M\', \' \', \' \',
 \' \', \'S\', \' \', \'M\', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \'E\', \' \', \' \', \'A\', \' \', \'B\', \' \', \' \',
 \' \', \'S\', \' \', \'U\', \' \', \' \', \' \', \' \', \' \', \' \', \'C\', \' \', \' \', \' \', \' \', \' \', \' \', \'E\', \' \', \' \',
 \' \', \' \', \' \', \'E\', \' \', \' \', \'M\', \' \', \' \', \' \', \'A\', \' \', \' \', \' \', \' \', \'R\', \' \', \'R\', \' \', \' \',
 \' \', \' \', \' \', \'N\', \' \', \' \', \'O\', \' \', \' \', \' \', \'M\', \' \', \'R\', \'I\', \'C\', \'O\', \'T\', \'T\', \'A\', \' \',
 \' \', \' \', \' \', \'S\', \' \', \' \', \'Z\', \' \', \' \', \' \', \'E\', \' \', \' \', \' \', \' \', \'Q\', \' \', \' \', \' \', \' \',
 \' \', \' \', \' \', \'T\', \' \', \' \', \'Z\', \' \', \' \', \' \', \'M\', \' \', \' \', \' \', \' \', \'U\', \' \', \' \', \' \', \' \',
 \' \', \'C\', \'H\', \'E\', \'D\', \'D\', \'A\', \'R\', \' \', \' \', \'B\', \' \', \' \', \' \', \' \', \'E\', \' \', \' \', \' \', \' \',
 \' \', \' \', \' \', \'R\', \' \', \' \', \'R\', \' \', \' \', \' \', \'E\', \' \', \'G\', \' \', \' \', \'F\', \' \', \'J\', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \' \', \'E\', \' \', \'G\', \'O\', \'R\', \'G\', \'O\', \'N\', \'Z\', \'O\', \'L\', \'A\', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \' \', \'L\', \' \', \' \', \' \', \'T\', \' \', \'U\', \' \', \' \', \'R\', \' \', \'C\', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \' \', \'L\', \' \', \' \', \' \', \' \', \' \', \'D\', \' \', \' \', \'T\', \' \', \'K\', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \'P\', \'A\', \'R\', \'M\', \'I\', \'G\', \'I\', \'A\', \'N\', \' \', \' \', \' \', \' \', \' \', \' \',
 \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \', \' \'
 };
 char words[18][11];
 int rindex=0,cindex=0,col=0,row=0;
 //We will check for every character in this loop
 for(int i=0;i<20;i++){
 for(int j=0;j<20;j++){
 if(crossword[i][j] !=\' \'){
 //If the top , left and right characters are empty then we will consider it as starting of a vertical word , we will print that
 if(crossword[i-1][j] == \' \' && crossword[i][j+1] == \' \' && crossword[i][j-1] == \' \' ){
 cindex=0,row=0;
 printf(\"%c \",crossword[i][j]);
 while(crossword[i+row][j] != \' \'){
 words[rindex][cindex++] = crossword[i+row][j];
 row++;
 printf(\"%c \",crossword[i+row][j]);
 }
 rindex++;
 printf(\"\ \");
 }
 //If the top , left and bottom characters are empty then we will consider it as starting of a horizantal word , we will print that
 else if(crossword[i-1][j] == \' \' && crossword[i][j-1] == \' \' && crossword[i-1][j] == \' \' ){
 //Horizantal Word
 cindex=0,col=0;
 printf(\"%c \",crossword[i][j]);
 while(crossword[i][j+col] != \' \'){
 words[rindex][cindex++] = crossword[i][j+col];
 col++;
 printf(\"%c \",crossword[i][j+col]);
 }
 rindex++;
 printf(\"\ \");
 }
 }
 }
 }
 printf(\"*******************************************************************\ \");
  //This nested loop is for printing all the words in the crossword puzzle style
 for(int i=0;i<18;i++){
 for(int j=0;j<11;j++){
 printf(\"%c \",crossword[i][j]);
 }
 printf(\"\ \");
 }
 return 0;
 }
![In C language!!! Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these s In C language!!! Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these s](/WebImages/27/in-c-language-write-a-program-that-finds-the-strings-in-the-1072942-1761562304-0.webp)
![In C language!!! Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these s In C language!!! Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these s](/WebImages/27/in-c-language-write-a-program-that-finds-the-strings-in-the-1072942-1761562304-1.webp)
![In C language!!! Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these s In C language!!! Write a program that finds the strings in the following hard-coded crossword puzzle character array named crossword[20][20], and copies these s](/WebImages/27/in-c-language-write-a-program-that-finds-the-strings-in-the-1072942-1761562304-2.webp)
