name swap in array

If I have a name in an array. (i.e. John Doe),
how can I get it too take "Jim Smith" and have it return "Smith, Jim."

Last edited on
Easy way: Create a spare array as a temporary, move everything after the first space to the temporary array, and then add a comma and a space and append everything before the first space to the end of that array. This is one way of doing it, but I'm not going to show you any code for it (you should do your own homework!).
Ya, I understand that part, basically it would be

string part1 = “John”;
string part2 = "Smith";
string total;

total = part2 + “, ” + part1;
cout << total << endl;

**so "Smith, John" will show up...I do get that.

What I'm confused with is how I can do it if I want to randomly enter the names into an array. lets say I enter John Smith and Jim Doe. I need to use the " " as a separator between the two names...not sure how to do that since each name may vary in length.


Topic archived. No new replies allowed.