Q.Using recursive function,reverse a string.
Solution I tried
#include<stdio.h>
#include<string.h>
char reverse(char *ptr,int length)
{
return ptr[0]=ptr[length-1];
while(*ptr!='\0')
reverse(ptr+1,length-2);
}
int main(void)
{
char string[40],answer;
printf("Enter string\n");
gets(string);
answer=reverse(string,strlen(string));
printf("%c",answer);
return 0;
}
It gives an error sayin 'Unreachable code in function reverse(char near*,int)' because of the line while(*ptr!='\0') Help plz! Would really appreciate if you could make corrections in my code instead of providing me with a readymade one.