What's the best method to split a string variable that holds someones full name (ex John Smith) and put the first name and last name into separate string variables? I know that searching for the space is the best way to start I'm just not sure how to go about it.
How do you split a string of multiple words into single words
Collapse
X
-
Matt BorbaTags: None -
find the first space and store the word up to the space in to a string of name 'first name' and continue the process untill '\0' reachComment
-
Is the input string read-only?
Do you need this input string for anything else?
If the answer to both questions is NO, then you can change the input string into two strings by replacing the first whitespace character between the first and last names with null ('\0') and return two pointers into the original string -- one to the first character of the first name and the other to the first character of the last name.Comment
Comment