Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I reverse a string using pointer and recursion using C ?
Posted
Updated 7-Mar-14 5:55am
v2
Comments
_Asif_ 7-Mar-14 11:54am    
We don't do home work :) and by the way what have u tried so far?
Sergey Alexandrovich Kryukov 7-Mar-14 12:04pm    
Using recursion here is a bad idea. Use just the loop.
—SA

1 solution

C#
int ReverseString(char *, int, int);
int main(void){
  char string[10] = "abcdefghi";
  ReverseString(string, 0, strlen(string)-1);
  printf("%s\n",string);
  return 0;
}

int ReverseString(char *str, int front, int end){
  if(front > end)
    return 1;
  else{
    char temp;
    temp = str[front];
    str[front] = str[end];
    str[end] = temp;
    front++;
    end--;
    ReverseString(str, front, end);
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900