I am new to the group and have noticed a lot of questions of recursion. A problem that is suitable for recursion should produce a smaller function that if the problem was solved without recursion. This has not been the case from the postings that i have looked at.
I have provided an example of recursion done correctly to reverse a string. Notice how short and compact the code is. This is the object of recursion - less code at the expense of more memory being used. Mickey M. senior software engineer http://www.constructionpartner.com // Reverse String char *RevStr(int count, char *str) { char Value; if (count) { Value = str[count-1]; RevStr(count-1, str); } if (count) str[strlen(str) - count] = Value; return(str); } int main(int argc, char* argv[]) { char Test[20] = "ABCDEFGHIJK"; char Out[20]; strcpy(Out,RevStr(strlen(Test), Test)); return 0; } //-------------------------------------------------------------------- -------
