In this project, you will write a C program that reads two input files:

  • puzzle.txt
  • words.txt

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:

APPLE
STRAP
SMALL
QUEEN
...

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).

PART A

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
char puzzle[MAXROWS][MAXCOLS]

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).

PART B

Now, improve your program to search for all possible orientations: N, E, W, S, NE, NW, SE, SW.

PART C

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:

PuzzleRows
PuzzleCols
Words, one by one
Follow these steps to achieve this:
  • First, create the words.txt file. This is a matter of making a file that contains the words the user just entered ...
  • Next, Create a string with so many rows and columns. This 2D array will be identical to the one you are using to read your string in your PART A.
  • Fill each individual character with randomized characters ... Do not exceed the 'A' ... 'Z' range, since otherwise it will be invalid characters. To create a random value ranging between 'A' and 'Z', use the C function rand(). This function is contained in the standard C library. I won't tell you where. You have to do this much research to get the bonus points !!!
  • Next, pick a random orientation, one of the ones in the list above, and implant every word one by one into your 2D puzzle array.
  • Write that array as puzzle.txt into the file. This is basically what you will use to test your program with more sophisticated puzzles in PART A, and PART B.

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.

PART D

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.