reversing strings

how do you reverse a string? For example if the string is 123 and you want it changed to 321.
 
Last edited on
Get a deck of cards, ¿how would you reverse it?
What? How does that relate to the problem?
Last edited on
closed account (S6k9GNh0)
It's a real life example of how to solve the programming problem. The answer to both are (or can be) the same.
Last edited on
oh, um I'd make the last one the first and go from there.
Is there a reverse function or something? I couldn't find one.
Yes, there is. But it has it's draw backs. A simple Google search would show you that the algorithm header has a reverse function. Though I would recommend making your own reversing algorithm.
I don't even know where to start to make a reversing algorithm. Can someone at least give me a hint or idea of how to?
closed account (S6k9GNh0)
Wat.... pretty sure you're over complicating.

Make two strings. Put the last character in the source string as the first character in the destination string. So on...
but how do you get the characters starting from the last?
I haven't learned how to use arrays yet :(
I deleted my previous post because using an array is an over complication. Check out these two links and it should help you understand what you will be doing.

http://www.cplusplus.com/reference/string/string/
http://www.cplusplus.com/reference/array/array/

And so you aren't blindly looking around. You will be using the [] operator.

Note: Even though using an array is over complicating things. It does help to know about them.
Last edited on
Topic archived. No new replies allowed.