If you would be so kind to go to this url, where I have already posted my problem and give me some tips on this forum or on the one already posted:

http://www.linuxquestions.org/questions/showthread.php?s=&threadid=387067

Thanks in advance,

P.S. This is really urgent, and it is probably a small problem.

Some updated code is here:

int RecursiveSearchLeft (char letters
			 [LETTERARRAYROWSIZE][LETTERARRAYCOLUMNSIZE],
			 int row, int column, WORD *words,
			 int wordIndex)
{
   int characterIndex = 0;
   
   if (letters [row][column] ==
       words [wordIndex].word [characterIndex] &&
       characterIndex <= strlen (words [wordIndex].word))
   {
      if (characterIndex == 0)
      {
	 words [wordIndex].startRow = row;
	 words [wordIndex].startCol = column;
      }
      
      characterIndex++;
      
      if (characterIndex == (strlen (words [wordIndex].word) - 1))
      {
	 return 1;
      }
      
      RecursiveSearchLeft (letters, row, column - 1, words,
			   wordIndex);
   }
   else if (column > NOBUFFERSTARTCOLUMN)
   {
      RecursiveSearchLeft (letters, row, column - 1, words,
			   wordIndex);
   }
   else if (column == NOBUFFERSTARTCOLUMN && row < NOBUFFERENDROW)
   {
      RecursiveSearchLeft (letters, row + 1, NOBUFFERSTARTCOLUMN,
			   words, wordIndex);
   }
   
   words [wordIndex].startRow = 0;
   words [wordIndex].startCol = 0;
   
   return 0;
}

Thanks, Mistro116

Using some debug lines, I have ALMOST completed the coding:

I'm basically stuck on why the following code will not return 1 when it finds the word. It does everything properly, comparing the letters, but then it gets to a point where a letter in the 2-d array is compared with nothing.. and thus it returns 0, why is this? I checked for null pointer / end line pointer for my word, but it just doesn't seem to work.

Here is some updates:

int RecursiveSearchLeft (char letters
			 [LETTERARRAYROWSIZE][LETTERARRAYCOLUMNSIZE],
			 int row, int column, WORD *words,
			 int wordIndex, int characterIndex)
{
   
   printf ("%c", letters [row][column]); /* Debug Line */
   printf ("%c\n", words [wordIndex].word [characterIndex]); /* Debug Line */
   if (words [wordIndex].word [characterIndex] == letters [row][column])
   {
      if (characterIndex == 0)
      {
	 words [wordIndex].startRow = row;
	 words [wordIndex].startCol = column;
      }
      
      if (characterIndex < strlen (words [wordIndex].word))
      {
	 RecursiveSearchLeft (letters, row, column - 1, words,
			      wordIndex, characterIndex + 1);
      }
      
      return 1;
   }
   else
   {
      characterIndex = 0;
      words [wordIndex].startRow = 0;
      words [wordIndex].startCol = 0;
      
      if (column > NOBUFFERSTARTCOLUMN)
      {
	 RecursiveSearchLeft (letters, row, column - 1, words,
			      wordIndex, characterIndex);
      }
      else if (column == NOBUFFERSTARTCOLUMN && row < NOBUFFERENDROW)
      {
	 RecursiveSearchLeft (letters, row + 1, NOBUFFERENDCOLUMN,
			      words, wordIndex, characterIndex);
      }
      
      return 0;
   }
}

Thanks,

Mistro116

Hmm, a tricky question (well it took some time to figure out what you are doing anyway)... It looks as thought you dont save the recursive result anywhere so that even if you get a match somewhere in the recursion you will only report a match if you get a match on the first location... Due to the same reason you probably will report match as long as the first character matches since you will do the whole search and totally disregard the result and return 1 anyway...

*hint store result from RecursiveSearch and se if it matched before returning something...

Thanks,

Yes the return value of the preprocesses was one issue. I've written all the code for this, but thanks for your input. I had to check a thousand things to make sure errors were avoided, but it worked :)

Thanks for the help.

Mistro116

This article has been dead for over six months. Start a new discussion instead.