Thread: reverse a string in place

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    13

    reverse a string in place

    how to reverse a character string inplace using recursive functions

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Code:
    #include <stdio.h>
    
    void rev(char *s)
    {
       if ( *s != '\0' )
         rev(s+1);
       putchar(*s);
    }
    
    int main(void)
    {
       rev("citizen gets paid by lazy students.");
       putchar('\n');
       return 0;
    }
    I hope you fail your course.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    13
    thank you sir for the soliution as well as the suggestion. now i am no more a failure

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > now i am no more a failure
    ROFLMAO

    No, your success depends on being spoon-fed by others.

    Success is doing it yourself, not getting lucky by finding an answer on a message board.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  4. Replies: 7
    Last Post: 03-18-2003, 03:32 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM