In this project, you will write a C program that reads two input files:
The puzzle.txt file will contain a Word puzzle in which many words are hidden. the words you will search for are listed in the words.txt file. Each line in the puzzle.txt corresponds to one row of the puzzle. For example, a 40x40 puzzle has 1,600 letters in it, some of which contain the hidden words. An example puzzle.txt and words.txt have been provided for you.
For example, look at the following 10x10 puzzle I am displaying to make the functionality of this program clear :
puzzle.txt file :
A J G D R H J O V K
A Z G D L L A M S K
A J G D R H J T V A
B Y G D R H R O V W
A J G A R A J O V K
W J G D P H J O V K
A V G D R P J O V Q
A J G D R H L O V K
C F G D R H J E V K
J J G D R H J O E K
Can you pick out the words APPLE, STRAP, and SMALL inside it ? So, your words.txt could have this:
The output of your program will look like this:
Word APPLE found at Row 5, Column 4, Orientation SE
Word STRAP found at Row 2, Column 9, Orientation SW
Word SMALL found at Row , Column, Orientation W
Word QUEEN not found
As you see, although the C language index of the array you will store this puzzle in might be different, you have to display the row and column numbers in a user-friendly manner. You will call the very top row (ROW 1) and the very bottom row in this case is ROW 10. Similarly, the leftmost column is COLUMN 1, and the rightmost column is COLUMN 10. The orientation of the words can be E, W, S, N, SE, SW, NW, NE.
An EAST (E) word is a word that starts on the left and extends to the right. A WEST (W) word is the one that starts on the right and goes backwards (just like SMALL in this example). SE and SW are the ones that extend diagonally to SOUTHWEST (and SOUTH EAST). Notice that the diagonal cannot have an arbitrary angle. Only perfect diagonals are allowed : as shown in the example of APPLE and STRAP. Perfect diagonal means, every next character is next row, next column (i.e., indexes go up or down by one).
Use a 2D array to read your puzzle from a file. Naturally, every line should be a string, each string being a size-N char array. Assume that, the puzzle cannot exceed 40x40 and assume that the puzzle is always a square. Completely ignore the spaces of any sort. Only pick out the letters from 'A' to 'Z'. Ignore the case of the letter. Turn every letter into its upper-case equivalent.
So, your puzzle string will look like this:
#define MAXROWS 40
#define MAXCOLS 40
I won't tell you how to define the words array. It is almost the identical idea. Implement this puzzle search only for the most natural "E" orientation (i.e., words go from left to right and there are no diagonals).
Now, improve your program to search for all possible orientations: N, E, W, S, NE, NW, SE, SW.
Write a program that creates puzzle.txt and words.txt. For this, your puzzlemake.c program should ask the user for two parameters and all of the words:
Words, one by one
Follow these steps to achieve this:
Note : You cannot advance to PART D without completing PART A, B and C. Notice that, you do not need to complete PART C to be able to finish PART A and PART B, since you can simply use the puzzle.txt and words. txt I provided.
Now, improve your program so that, it has NO LIMITATION ON THE PUZZLE SIZE and also the PUZZLE CAN BE A RECTANGLE. Call your puzzle size PuzzleRows x PuzzleCols. You have to allocate the memory for the puzzle using malloc() to qualify for the bonus in this question. If you forget to free() the memory you allocated, you will lose bonus points, since your program will be a memory-leaky program. You will read the file puzzle.txt and figure out the puzzle size dynamically, and do the puzzle search in every orientation. Notice that, to qualify for the bonus in PART D, you have to submit PART A (puzzle1.c) and PART B (puzzle2.c) and PART C (puzzlemake.c) separately first. This submission on PART D (puzzle3.c) is a completely separate program.
No need to say, to qualify for the bonus PART D points, you have to write a NO-LIMITATION version of your puzzlemake.c. You can write only this version if you are going for PART D bonus points.