I've gotten to a stage in my program where I'm testing runtime efficiency and I want to write a recursive function that will search a 2-dimensional array of characters for a words.
I'm trying to write the function for SearchLeft, where it will search entirely to the left throughout the entire grid of characters until it either finds the word or it doesn't and changes the value of its starting row and column; however, it's not finding the word, so I think there may be a few problems with it.
Here is my code so far:
Code:
int RecursiveSearchLeft (char letters
[LETTERARRAYROWSIZE][LETTERARRAYCOLUMNSIZE],
int row, int column, WORD *words,
int wordIndex, int characterIndex)
{
if (words [wordIndex].word [characterIndex] ==
letters [row][column])
{
if (characterIndex == 0)
{
words [wordIndex].startRow = row;
words [wordIndex].startCol = column;
}
characterIndex++;
if (characterIndex < strlen (words [wordIndex].word))
{
RecursiveSearchLeft (letters, row, column - 1, words,
wordIndex, characterIndex);
}
return 1;
}
else if (column == NOBUFFERSTARTCOLUMN && row <= NOBUFFERENDROW)
{
RecursiveSearchLeft (letters, row + 1, column + 14, words,
wordIndex, characterIndex);
return 0;
}
else
{
RecursiveSearchLeft (letters, row, column - 1, words,
wordIndex, characterIndex);
}
return 0;
}
The sample 2-d array would be:
Code:
EHUKXDICNMYTYLF
WOCJSKLTIMHONII
NOTGNIHSAWZIFNP
IRBWNIIWPPIERCE
BMETVELIIOKOWOK
QUOWCLEVELANDLN
VNCCOORTHTSNUNA
AMKHRHFELSIONOM
DULNAANETXUQNSU
AIOATNVEORKBARR
MMPZVEANSUALBET
SYSDSWGNBITCLFI
OHZOMYDENNEKWFD
IAOTNARGRNVTFEF
KRRVFVEEDMBDMJZ
Specifically, I'm testing this by searching for the word GRANT, which is on row 14, col 8.
What is wrong with this code? Can anyone help? It's urgent.
Thanks once more,
Mistro116
Edit: The 2-d array has a buffer around it:
Code:
XXXXXXXXXXXXXXXXX
XEHUKXDICNMYTYLFX
XWOCJSKLTIMHONIIX
XNOTGNIHSAWZIFNPX
XIRBWNIIWPPIERCEX
XBMETVELIIOKOWOKX
XQUOWCLEVELANDLNX
XVNCCOORTHTSNUNAX
XAMKHRHFELSIONOMX
XDULNAANETXUQNSUX
XAIOATNVEORKBARRX
XMMPZVEANSUALBETX
XSYSDSWGNBITCLFIX
XOHZOMYDENNEKWFDX
XIAOTNARGRNVTFEFX
XKRRVFVEEDMBDMJZX
XXXXXXXXXXXXXXXXX