#include #include // findspaceInd("John Doe") --> 4 int findspaceInd(string s) { int i; int answer; i = 0; answer = s.size(); // no space found while ( i "defg" string substring(string s, int start, int length) { string answer; int i; // loop counter answer = ""; i = start; while (i "John" string firstname(string s) { int si; // index of the space char string answer; si = findspaceInd(s); if (si == s.size()) // no space answer = s; else answer = substring(s,0,si); return answer; } string lastname(string s) { int si; // index of the space char string answer; si = findspaceInd(s); if (si == s.size()) // no space answer = s; else answer = substring(s,si+1,s.size()-(si+1)); return answer; } int main() { cout << firstname("John Doe") << endl; cout << lastname("John Doe") << endl; return 0; }