output should like that: input #: (909)869-2511 area: (909) exchange: 869 ext.: 2511 #: (909)869-2511 this is my code so far: Code: #include <iostream> #include <iomanip> #include <cstring> using namespace std; int main() { char sentence[32]; char *tokenPtr; tokenPtr = &sentence; cout << "Input Telephone No.: " ; cin >> sentence; tokenPtr = strtok( sentence, " " ); while ( tokenPtr != NULL ) { cout << tokenPtr << '\n'; tokenPtr = strtok( NULL, " " ); } return 0; }
I don't think I'd use strtok for that, just loop through the input string and pick out groups of digits.