I am trying to reverse a word using recursion in c
and i got upto this.
#include<stdio.h>
void reverse(char *a){
if(*a){
reverse(a+1);
printf("%c",*a);
}
}
int main() {
char a[] = "i like this program very much";
reverse(a); // i ekil siht margorp yrev
return 0;
}
Suppose the input string is i like this program very much
. The function should change the string to much very program this like i
Algorithm:
1) Reverse the individual words, we get the below string.
"i ekil siht margorp yrev hcum"
2) Reverse the whole string from start to end and you get the desired output.
"much very program this like i"
I have successfully completed up-to step 1 and i am not sure how to proceed further. Please help.