![]() |
|
#1
|
|||
|
|||
Finding a word in a 2d gridHi all,
I was asked to make a mystery word game (find some word in a grid to reveal tthe hidden word) and to do this I need to make a function that search for a word in my grid and returns his coordinates and the direction it was found in the grid. Once the first letter of the searched word matches the grid's letter, the word can be in the 8 directions so we need to check this out. I have made a function but I'm having problems returning the correct coordinates and direction. If anyone could give a little help pointing me what I'm doing wrong, I would really appreciate ! Here it is: CPP / C++ / C Code:
Thanks a lot for the help, Frank Last edited by LuciWiz : 25-Feb-2005 at 01:01.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
|
Quote:
There's not much chance that I will be able to read through your code to check functionality. One glaring error that must be fixed: CPP / C++ / C Code:
You allocate an array (with new) and set the pointer arrGrid to the address of its first element. Then you immediately set the pointer arrGrid to the value of an address passed in as an argument. (So you can never free the memory --- by the way, where do you delete it? You know that you must delete everything that new gave you: right?) You probably want strcpy() to copy whatever into the memory that you got from new. (But it's kind of hard to tell since I have nothing that I can actually compile and execute.) You have a comment that indicates that you think you know where your problem is. Great! Now, put some output statements in and around the suspected block to see what's really happening Regards, Dave |
|
#3
|
|||
|
|||
|
Thanks Dave for the comments.
As you thaught, I didn't knew we had to delete a created object . I'm still freshly new in C++ and with the previous language, this wasn't necessary. Like you said, I know where the problem is but don't know how to solve it. I was given a function (that i can't touch) that fill an array with each line of the grid as a different item. I'll continue working on this, if anyone has suggestions please let me knoe... Thanks guys, Frank |
|
#4
|
|||
|
|||
|
Quote:
Do you have any control over program parameters? I mean: can you create a test case with a small grid or what? You seem to indicate that you can't control what gets put into the grid --- is this the case? If you can control the input in some way, then put in a small grid and a small word and run it through your function. If not, then I suggest you print out whatever grid you are given, find a word (by inspection) and call your program to see if it can find the word. Put output statements that show how you are tracking through the grid while looking for the word. Something like that. Regards, Dave |
|
#5
|
|||
|
|||
|
Actually I'm able to find the first letter of a word in the grid and return it's coordinates. It's the testing after that that cause the problem
I don't know, from there, how to check every direction to find the second letter of the word. I know to solve the current issue with my function I should create and call a new function called findNextLetter that would check every direction for a possible match, but I simply don't know how to do it... Search for "word search" everywhere on the web but looks like I'm having no luck tonight... Desperate dude. |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| won't read file from disk, dunno why | wbsquared03 | C++ Forum | 3 | 29-Nov-2004 11:19 |
| I am reviewing Arrays and need help converting some strings to arrays | jenmaz | C Programming Language | 22 | 22-Nov-2004 23:26 |
| How to do word comparison in C++ ? | mail_as | C++ Forum | 19 | 22-Jun-2004 17:39 |
| testing word file "need help" | alexandro | C Programming Language | 2 | 03-Jun-2004 14:38 |
| coding a word with a givin factor | funnyf | C++ Forum | 2 | 13-Jan-2004 08:32 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The