I am currently studying C and I can\'t get past this exercise. I must create a recursive function to reverse string1
into string2
. Here is my code. I w
Although it does not save the resulting string anywhere, you get the idea.
#include
void rev (const char* str);
int main () {
const char str[] = "!dlrow ,olleH";
printf("%s\n", str);
rev(str);
printf("\n");
return 0;
}
void rev (const char* str) {
char c = *str;
if (c != '\0') {
rev(str + 1);
printf("%c", c);
}
}