Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

puzzle1.txt W D B M J Q D B C J N Q P T I I R Z U X U Z E A

image text in transcribed

puzzle1.txt

W D B M J Q D B C J N Q P T I I R Z U X U Z E A O I O R T N M N Z P L R N H L Y L X H M D M Y E K A I D P I U L Y O W I A O A B A R K U F V I H L A A L O N M R X K I O J N A V R N A E P T A A R A R T O W A I A S U C Z A U S I N A I A L Z V K O T A O N R K I S S I A O N A H X S V K A I A E A I B N E U D S X N X C C D W G S A A V O I S D W L E J N J T X M H A M O X W T N H Q D X O Q A Q D R U U V G E O R G I A Q V D A V F L O R I D A L G L W O X N

Words you will be searching for:

states.txt

Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada NewHampshire NewJersey NewMexico NewYork NorthCarolina NorthDakota Ohio Oklahoma Oregon Pennsylvania RhodeIsland SouthCarolina SouthDakota Tennessee Texas Utah Vermont Virginia Washington WestVirginia Wisconsin Wyoming

given code:

wordsearch.c

#include #include #include

// Declarations of the two functions you will implement // Feel free to declare any helper functions void printPuzzle(char** arr, int n); void searchPuzzle(char** arr, int n, char** list, int listSize);

// Main function, DO NOT MODIFY!!! int main(int argc, char **argv) { int bSize = 15; if (argc != 2) { fprintf(stderr, "Usage: %s ", argv[0]); return 2; } int i, j; FILE *fptr; char **block = (char**)malloc(bSize * sizeof(char*)); char **words = (char**)malloc(50 * sizeof(char*));

// Open file for reading puzzle fptr = fopen(argv[1], "r"); if (fptr == NULL) { printf("Cannot Open Puzzle File! "); return 0; }

// Read puzzle block into 2D arrays for(i=0; i

fscanf(fptr, "%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c ", *(block+i), *(block+i)+1, *(block+i)+2, *(block+i)+3, *(block+i)+4, *(block+i)+5, *(block+i)+6, *(block+i)+7, *(block+i)+8, *(block+i)+9, *(block+i)+10, *(block+i)+11, *(block+i)+12, *(block+i)+13, *(block+i)+14 ); } fclose(fptr);

// Open file for reading word list fptr = fopen("states.txt", "r"); if (fptr == NULL) { printf("Cannot Open Words File! "); return 0; } // Save words into arrays for(i=0; i

// Call searchPuzzle to find all words in the puzzle searchPuzzle(block, bSize, words, 50); printf(" "); // Print out final puzzle grid with found words in lower case printf("Printing puzzle after search: "); printPuzzle(block, bSize); printf(" "); return 0; }

void printPuzzle(char** arr, int n){ // This function will print out the complete puzzle grid (arr). It must produce the output in the SAME format as the samples in the instructions. // Your implementation here

}

void searchPuzzle(char** arr, int n, char** list, int listSize){ // This function checks if arr contains words from list. If a word appears in arr, it will print out that word and then convert that word entry in arr into lower case. // Your implementation here

}

Word Search Puzzle A word search puzzle is a game that you are asked to find a given list of words from a grid of letters. If you do not know about this puzzle, please visit: https://en.wikipedia.org/wiki/Word_search to find out more about how this puzzle works. Description of wordsearch.c The main program (wordsearch.c) is given to you. Your tasks are to implement 2 functions to complete the program. When the program starts, it will read the puzzle grid from a text file and save it as a 2-D character array. It will also read a list of words from another text file and save the list into a string array. The program will search for words in 5 directions: horizontal left to right), vertical top to bottom (1), vertical bottom to top (1), diagonal top left to bottom right), and diagonal bottom left to top right(). Your Tasks printPuzzle(char**, int) - This function takes in the puzzle grid with its dimension (assuming a square grid) and prints out its content. Implement this function so that it will print out the content in the SAME format as the sample output. searchPuzzle(char**, int, char**, int) - This function is the core of solving the puzzle. It takes in the puzzle grid with its dimension and tries to find as many words listed in the word list (the 3rd input argument). Not all words will be found from the grid. Whenever a word is found, your program will print it out as well as converting the word in the puzzle grid to lower case. YOU MUST NOT USE ANY ARRAY NOTATION (1) IN THIS PROGRAM! YOU MUST NOT USE ANY LIBRARY FUNCTIONS TO CONVERT CHARACTERS INTO LOWER CASE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

explain what is meant by redundancy

Answered: 1 week ago