reverse a string in place

This is a discussion on reverse a string in place within the C Programming forums, part of the General Programming Boards category; how to reverse a character string inplace using recursive functions...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,666
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:40 AM
  4. Replies: 7
    Last Post: 03-18-2003, 02:32 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21