Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
Many of you would have seen a paper-and-pencil game in which a table of alphabets is presented. When one looks at this for the first time, it is likely that only a seemingly random set of alphabets are present. On close look, one can discern that there are meaningful words "hidden" along particular rows and columns. See if you can discover the word NIGHTLY tucked away in rows and columns.
 
R N I G H T L Y I Y
X I T W Q L Z N O V
A G Y B X M N U Y L
Q H N O T F V J K N
V T M I D O U Y R I
P L B X G G K I F G
R Y K F N H E N O H
V J F D K T T C M T
H D X Z W Q N L T L
V B C O K H F T Y Y
 
It is required to write a complete C program that takes a word maze as input from the user, and store this in an appropriate data structure. Then the user is given a word to be searched in the maze. The program must locate all occurrences of this word in the maze along Horizontal and Vertical directions.
 
Once the locations of the word are found in the maze, the program must also replace all other characters in the maze which are not part of the located words, by the 'space' character. The program must display the maze which now has only the locations and occurrences of the word searched for.
 

You are given an enum
 
typedef enum {
TOP = 0,
LEFT,
RIGHT,
BOTTOM,
} DIRECTION;
This enum represents different directions as the names suggests. The direction representation is as following:
TOP : from BOTTOM towards TOP
LEFT : from RIGHT towards LEFT
RIGHT : from LEFT towards RIGHT
BOTTOM : from TOP towards BOTTOM
 
You are required to write 2 functions:
 
1. void trimMaze(char maze[MAX_ORDER][MAX_ORDER], int orderOfMaze, char word[])
This function receives a two dimensional array maze and the orderOfMaze. Number of rows and columns in the maze are equal to the orderOfMaze. The function also receives the word which needs to be searched. You are required to locate all occurrences of the word that needs to be searched and replace all other characters with 'space' characters in the maze which are not part of the located words and store the result back in two dimensional array maze.
 
Example:
the maze is:
 
r a t a t
r s b c a
a e t a r
t b c d a
r a t w z
 
the word that needs to be searched is: "rat".
then after trim maze will be like:
r a t t
r a
a t a r
t
r a t
 
2. int getPositions(int positions[MAX_POSITIONS][NUM_OF_ATTRIBUTES], int posLength, char word[], char maze[MAX_ORDER][MAX_ORDER], int orderOfMaze, DIRECTION d, int r, int c)
This function receives a two dimensional positions array. In positions array every row represents a position of the word whereas columns represent the Indexes and directions of the word. In positions array first column represents the rowIndex of the word, second column represents the columnIndex of the word and third column represents DIRECTION in which word was found.
By Index we mean the array index of the word's starting letter.
Example:
If word ABC has indexes in array:
A: row- 0 col- 3
B: row- 0 col- 4
C: row- 0 col- 5
 
Then in positions array the first row will have
0 3 RIGHT
Note that the direction is RIGHT because the word was found while searching from LEFT towards RIGHT.
 
The function also receives length of the positions array which is posLength. As you find positions of the word you have to append those positions to the array positions and at the end you have to return the new length of the positions array.
 
The function also receives the word which needs to be searched, the maze in which you need to search the word, order of the maze, direction towards which you have to search the word.
The function also receives row index r and column index c which represents the row column indexes from which you have to start searching the word.
Example:
If parameters passed are
r = 1
c = 0
d = BOTTOM
order of maze = 10
then indexes you will search are:
(1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0),(9,0)
Posted 28-Mar-13 3:23am
Comments
ThePhantomUpvoter at 28-Mar-13 8:26am
   
And your question about your homework is what?
nv3 at 28-Mar-13 8:45am
   
See the question "how to do horizontal and vertical search for a word in a 2 dimensional character Array using c" by your class mate. I have to admit, he didn't even take the time to specify the problem as nicely as you did. Nevertheless, this is a simple task in C and it is your exercise, not ours. If you don't like to work on such problems, better not try to become a software developer. You will hate it.
Member 9949263 at 28-Mar-13 8:56am
   
for ( int i = 0; i <= MAX_ORDER-1/19; i++)
for ( int j = 0; j <= MAX_ORDER-1/19; j++)
for ( int k = 0; k<= len; k++) //len is lenght of word
if(maze[i][j])==word[k])
maze[i][k]=' ';
Member 9949263 at 28-Mar-13 8:56am
   
is it correct?
Jonathan [Darka] at 28-Mar-13 9:21am
   
Why not try it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Do yourself your own homework: it is a pretty effective way of learning.
And, please, read the FAQ.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just posting your homework assignment here is not going to get someone to do it for you. Review your class notes and textbook and try to do something for yourself. You will learn a lot more that way.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 485
1 OriginalGriff 310
2 Shweta N Mishra 244
3 Mathew Soji 225
4 BillWoodruff 200
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100