reverse word and character in string

September 2, 2010 at 20:52:07
Specs: Windows XP
I need a program that inputs a string in c or c++. It then displays the string first with the words reversed and the second with the characters reversed in each word.

Like this:
Sample run:
Input string: My name is Maui!

Output: Maui! is name My
!iuaM si eman yM


See More: reverse word and character in string

Report •


#1
September 2, 2010 at 20:56:46
I forgot, c or c++

Report •

#2
September 2, 2010 at 22:13:01
This looks like a homework question.
Sorry, but we don't do that here.

Report •

#3
September 3, 2010 at 13:29:21
You didn't specify whether or not it's a c-style string or a string class object, but for a c-style string, at least, the entire string can be reversed using a loop starting at strlen - 1 until 0; output each character using cout.put, putchar, printf("%c", ..), etc. For the other one, you *might* try strrchr using the space as a deliminator.

The string class has a lot of neat little class member functions for stuff like this IIRC.

HTH

-------------------------------------------
I have no aspiration for preaching. ;-)


Report •

Related Solutions

#4
September 3, 2010 at 16:43:40

Report •


Ask Question