Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So basically, I have to write a program in C. The following are the instructions. Word Search is a popular puzzle game that consists of

So basically, I have to write a program in C. The following are the instructions.

Word Search is a popular puzzle game that consists of a grid of alphabetical letters, and a number of words that players have to find within the grid. The words are formed by a series of contiguous letters in the grid along a single direction, where the direction is one of: forward, backward, upward, downward, No curved words may exist, and words cannot continue on to the next line or the next column. Your task is to write a program store the followind pattern: (SHOWN BENEATH) and lets the user repeatedly specify words to be found in the grid. If a specified word is successfully found, the program will alter the grid such that the letters of the word become capitalized. If the user enters the word QUIT, the program will end. You may assume that the puzzle grids provided will always be square, and always contain alphabetical characters. They will be provided in files where the first line is a number indicating the size of the grid (the width/height), followed by each row of the puzzle.

TO WRITE THIS CODE, YOU MUST MAKE USE OF THE GIVEN FUNCTIONS AND YOU SHOULD NOT ALTER THE MAIN FUNCTION!

I PERSONALLY HAVE WRITTEN THE FIRST TWO FUNCTIONS. I JUST NEED HELP WITH THE REMAININNG THREE FUNCTION(TWO ALREADY IN THE SKELETON AND MAKE ONE NEW ONE)!

THIS IS THE PUZZLE

10

h g a m o n i h r a

a o m o k a w o n

s n f r o l b o b d n

a r f s i h c a g e l

n i e e w o n o k g

o l f u n d t h c k o

c a t a o h b i a m r

e r c g a n h s l g f

a m a l l c a l l i g

a t o r x

THIS IS THE SKELETON WITH MY WORK INCLUDED IN IT.

#include #include #include #include #include

#define MAX_WORD_LEN 20 #define MAX_COL 20 #define MAX_ROW 20 #define MAX_FILENAME 100 #define QUIT_KEYWORD "QUIT"

/* APS105 students *MUST* make use of the functions prototyped below */

/* Prompts the user for an input file to read from. * Parses the input file and stores the puzzle into the 2D array provided. * Stores the size of the puzzle using the integer pointer provided. * Returns 'true' if successful, 'false' if something went wrong. */ bool readPuzzle(char cGrid[][MAX_COL], int *pdPuzzleSize) {

int i = 0, j = 0; char myPuzz [MAX_FILENAME];

// printf("File name: "); // scanf("%s", &puzzFile);

printf("Please enter the files name: "); scanf("%s", myPuzz);

FILE *puzzle3; puzzle3 = fopen(myPuzz, "r");

if (puzzle3 == NULL) { printf("The program failed to open. Exiting Program..."); return false; }

fscanf(puzzle3, "%d", pdPuzzleSize);

if (*pdPuzzleSize > 20 || *pdPuzzleSize < 4) { printf("The Size of the puzzle is not compatible."); exit(1); }

for (i = 0; !feof(puzzle3) && i < *pdPuzzleSize; i++) { for (j = 0; !feof(puzzle3) && j<*pdPuzzleSize; j++) { fscanf(puzzle3, " %c", &cGrid[i][j]); } } for (i = 0; !feof(puzzle3) && i < *pdPuzzleSize; i++) { for (j = 0; !feof(puzzle3) && j< *pdPuzzleSize; j++) { printf(" %c", tolower(cGrid[i][j])); } printf(" "); }

fclose(puzzle3);

return true; }

/* Queries the user for a word to search, storing it in the string provided */ void readSearchWord(char searchWord[], int dPuzzleSize);

/* Finds the search word in the 2D array provided */ void findWordInPuzzle(char cGrid[][MAX_COL], int dPuzzleSize, char searchWord[]);

/* High-level main function. APS105 students *MUST NOT* modify this function */ int main() { int i = 0, j = 0; char cGrid[MAX_ROW][MAX_COL] = {0}; char searchWord[MAX_WORD_LEN + 1] = {0}; bool status = true; int dPuzzleSize = 0;

// Read puzzle from file status = readPuzzle(cGrid, &dPuzzleSize);

if (status) { // Print the grid that was read in, then query // the user for a string and try to find it printPuzzle(cGrid, dPuzzleSize); readSearchWord(searchWord, dPuzzleSize);

// If the entered word isn't 'QUIT', continue... while (strcmp(searchWord, QUIT_KEYWORD)) { printf("Searching for the word: %s ... ", searchWord); findWordInPuzzle(cGrid, dPuzzleSize, searchWord); printPuzzle(cGrid, dPuzzleSize);

// Query user for string, then try to find it readSearchWord(searchWord, dPuzzleSize); } }

printf("Exiting program... "); return 0; }

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_2

Step: 3

blur-text-image_3

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago