Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do not add any new librarys other than the ones provided. Below is the provided Code to work on to complete the project. #include #include

image text in transcribed

image text in transcribed

image text in transcribed

Do not add any new librarys other than the ones provided.

Below is the provided Code to work on to complete the project.

#include

#include

#include

// Declarations of the two functions you will implement

// Feel free to declare any helper functions or global variables

void printPuzzle(char** arr);

void searchPuzzle(char** arr, char* word);

int bSize;

// Main function, DO NOT MODIFY

int main(int argc, char **argv) {

if (argc != 2) {

fprintf(stderr, "Usage: %s ", argv[0]);

return 2;

}

int i, j;

FILE *fptr;

// Open file for reading puzzle

fptr = fopen(argv[1], "r");

if (fptr == NULL) {

printf("Cannot Open Puzzle File! ");

return 0;

}

// Read the size of the puzzle block

fscanf(fptr, "%d ", &bSize);

// Allocate space for the puzzle block and the word to be searched

char **block = (char**)malloc(bSize * sizeof(char*));

char *word = (char*)malloc(20 * sizeof(char));

// Read puzzle block into 2D arrays

for(i = 0; i

*(block + i) = (char*)malloc(bSize * sizeof(char));

for (j = 0; j

fscanf(fptr, "%c ", *(block + i) + j);

}

fscanf(fptr, "%c ", *(block + i) + j);

}

fclose(fptr);

printf("Enter the word to search: ");

scanf("%s", word);

// Print out original puzzle grid

printf(" Printing puzzle before search: ");

printPuzzle(block);

// Call searchPuzzle to the word in the puzzle

searchPuzzle(block, word);

return 0;

}

void printPuzzle(char** arr) {

// 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, char* word) {

// This function checks if arr contains the search word. If the

// word appears in arr, it will print out a message and the path

// as shown in the sample runs. If not found, it will print a

// different message as shown in the sample runs.

// Your implementation here...

}

Project 01: Word Search Puzzle CSE-031-01 Points: 100 Overview In this projcct, we will usc all the topics we have learn about C to writc a program to solve Word Scarch Puzzles. Description of wordsearch.c The main program (wordsearch.c) is given to you. Your primary task is to implement the searchPuzzle( ) function 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. The first number in the text file containing the puzzle grid indicates the size of the grid. For instance, a 5 means the puzzle is a 55 grid. The program will then ask the user for the word to search and store it in the variable word. The program should then print the original puzzle grid and search for the word in the puzzle. The program should finally print whether the search word is found, and if so, the search path as described below. Your Tasks searchPuzzle (char**, char*) - This function is the core of solving the puzzle. It takes in the puzzlc grid to find the scarch word input by the uscr (the 2 nd argument) and prints the phrasc Word found! and the path(s) if the word is found. If the word is not found, then it prints Word not found. The search will happen in a case insensitive manner and all directions are allowed. The letters in the found word (i.c., the path) must be one index away from each other either in row or column or both (or in simpler terms, adjacent to each other) as shown in the sample runs. - YOU MUST NOT USE ANY ARRAY NOTATION ([]) IN THIS PROGRAM! - YOU MUST NOT USE ANY LIBRARY FUNCTIONS TO CONVERT CHARACTERS INTO LOWER/UPPER CASE! - YOUR OUTPUT FORMATTING MUST EXACTLY MATCH THE SAMPLE RUN IN TERMS OF SPACING, WORDING OF PROMPTS AND NEWLINES! Fecl free to create any helper functions and additional arrays to simplify your searchPuzzle function. To help further explain the expected behavior of your code, some examples follow along with explanation of the output: Sample Run (user input shown in blue, with each run separated by a dashed line): Enter the word to search: Hello Printing puzzle before search: W E B M O I L H L L M L Z E L MYEKO A O A B A Enter the word to search: bAnANa Printing puzzle before search: J Z I MOB 0 T HN G A E R B Q P W MAEKOZ A T N R A E E NOBTK Enter the word to search: deTeR Printing puzzle before search: J Z I D 0 E T H N E E R Z T R MDPKO A T F R A Enter the word to search: color Printing puzzle before search: J Z I D 0 E THN E E R Z T R M D P KO A T F R A Word not found! Explanation of Sample Runs Please note that for the first sample run shown above, the path output is not unique, but your solution needs to output only one of the many viable paths if those patbs overlap in the first letter (' H ). For example, other paths for this puzzle are as follows (which need not be output by your solution): For the second sample run, finding the word in the puzzle involves backeracking. Your solution must print the path as shown. Here 642 denotes that the character at this location is the 2mi,4th and 6th in the search path. Your program may also output 246 instead of 642 at this location (and subsequently, 35 instead of 53 at the othcr location shown in the output). For the third sample run, the program produces two path outputs as these paths do not overlap in the first letter (' D ). This is only a bonus feature and is worth 10 extra points (in addition to the 100 total points). For the basic solution, your program need not produce multple paths and a single one will suffice. Note that there is one more possible solution that is not shown since one of the paths overlaps in the first letter of the path shown in the sample run output: Testing Your Program After compiling wordsearch.c, run the program by typing ./wordsearch puzzle1.txt, where wordsearch is the executable file, and puzzle1.txt is the text file containing the puzzle grid. Feel free to create your own text files for test cases. Collaboration You must credit anyone you worked with in any of the following three different ways: 1. Given help to 2. Gotten help from 3. Collaborated with and worked togerher What to hand in When you are done with this project assignment, submit all your work through CatCourses. Before you submit, make sure you have done the following: - Your code compiles and runs on a Linux machine (without the necd for special libraries). - Attached wordsearch. c and any additional test files, pseudocode, idca sketches, notes, etc. - Filled in your collaborator's name (if any) in the "Comments..." text-box at the submission page. Also, remember to demonstrate your code to the TA or instructor before the deadline

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

Data Analytics Systems Engineering Cybersecurity Project Management

Authors: Christopher Greco

1st Edition

168392648X, 978-1683926481

More Books

Students also viewed these Databases questions