First Recursion Project

So our first assignment is recursion and i have almost completed it. I am just having a few issues with the recursive solutions to a c-string reversal and a char search within a c= string.

assignment link:
http://www.ittc.ku.edu/~niehaus/classes/268-f11/labs/recursion_intro/recursion_intro_lab.html

recap:
We have to create a iterative version and a recursive version of each function.

What i have:

The 2 parts i have issues with are
1
2
3
4
5
6
7
8
void str_reverse_r ( const char str1[], char str2[] )
{
  if( *str1 != '\0' )
    {
      *str2 = *str1;
      str_reverse_r(str1 + 1, str2 - 1);
    } 
}


This is the recursive version of the reverse string. My problem is the first letter of the reversed string is wrong ( it is the first letter of the non-reversed string) and after it does the first test from the input file (there are multiples lines in the file that are tested) i gets a segment failure and does not test the rest.

1
2
3
4
5
6
7
8
9
10
11
12
13
int str_char_find_r ( const char str1[], const char search_char )
{
  if (*str1 == search_char)
    {
      return str1;
    }
  else
    {
      return (str_char_find_r (str1+1, search_char));
    }
	    
  return -1;
}


This one is the search for the char. I am just overall having issues wrapping my head around this concept.

ANY help is appreciated!

Thanks in advanced.
Topic archived. No new replies allowed.