Sunday, July 12, 2009

Using C++ String manupulation...Help?

Using C++ how can I receive a string input given below:





User input: (First Name) (Last Name)





Then Print out:





Output: (Last Name) , (First Name)

Using C++ String manupulation...Help?
your getting a user input for first and last name seperated by a space. use the strtok() function to extract the strings on either side of the space. then print it in the format you want.
Reply:Its easy.


Use space as a delimiter. Scan the string from left to right whenever you encounter the space overwrite it with a NULL and go to the next position in the string and copy it in a new string till the end of the original string is encountered. When the end of the string is encountered put a space and after the space a NULL. Then concatenate the original string with this new string. Then you will get your answer.





I have told you the logic now its up to you to do the coding. I can do the coding but you must do your homework yourself.


No comments:

Post a Comment