Thread: Performing a destructive string reversal

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    36

    Performing a destructive string reversal

    Can anyone suggest a method as to how i can perform a destructive string reversal?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    What do you mean destructive? Are you trying to blow up the string? LOL.

    Or do you just want to reverse all of the characters in a particular buffer? In that case, have one pointer pointing to the start of the string and another one pointing to the end of it. Swap, swap, swap......

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I think he means reverse the string, destroying the original (ie doing it in the same var)?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    there are sample on the board - use search.
    Idea is to make two pointers: src is pointing to the beginning
    dst to the last char
    after copy char - you advance src one char forward and dst one char backward.
    You stop when dst <= src (in the midlle of the string)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    36
    ok guys... lets slow down, im a newbie here

    i dont even really know for sure what a destructive string reversal is...

    all i know is that, if i made an array of characters, and typed out a string, Hello, for example,

    the program would reverse the characters of the string, and print back to the screen olleH

    so ill try w/ the 2 pointers then, see where that leads me, i guess...

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    As vart said, create a pointer at the start and a pointer at the end, iterate through them (to swap the chars)... Just make sure you stop at the middle

  7. #7
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    see MacGyver's post, then see his sig.

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    36
    Quote Originally Posted by @nthony View Post
    see MacGyver's post, then see his sig.
    see this acronym: stfu

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    haha, good way to get help. You should go on freenode #c and ask the same question perhaps?

  10. #10
    Registered User
    Join Date
    Jun 2007
    Posts
    36
    Quote Originally Posted by zacs7 View Post
    haha, good way to get help. You should go on freenode #c and ask the same question perhaps?
    what is that?

  11. #11
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Somewhere, where you'd be put in your place...

  12. #12
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by sh4k3 View Post
    see this acronym: stfu
    If you want help, this is not how to get it. Move along to somewhere else.

  13. #13
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Here you go, it won;t take not 2 min to search the board
    http://cboard.cprogramming.com/searc...earchid=650471

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM