Recursion in c prog,,,

+2 Danny AA · January 17, 2015
Hello,
I need with recursion pls.
I'm trying to make Lexicographic function.

Here is what i have so far.

char*** lexicographinc(char* str1,  char* str2)
{
if (str1 == NULL || str2 == NULL)
return 0;
else
{
if (strcmp(str1, str2) == 0)
strcpy(str1, str2);
return lexicographinc(str1 + 1, str2 + 1);
}

}

It's not working.

Post a Reply

Replies

Oldest  Newest  Rating
0 Sheldon Juncker · January 18, 2015
The problem is that you continue to increment the pointers str1 and str2 until the pointers are reading garbage. You need to test for the ends of str1 and str2 in your function. 

Also strcpy() will only work if str1 is longer than str2.
  • 1

C

107,030 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator