(Tokenizing Phone Numbers) Write a program that inputs a telephone number as a string in the form (555) 555-5555. The program should use function strtok to extract the area code as a token, the first three digits of the phone number as a token, and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code
and the phone number should be printed.
What will be an ideal response?
```
#include
#include
#include
using namespace std;
int main()
{
const int SIZE1 = 20;
const int SIZE2 = 10;
char p[ SIZE1 ];
char phoneNumber[ SIZE2 ] = { '\0' };
char *tokenPtr; // store temporary token
char *areaCode; // store area code
char *phone; // store the phone number
cout << "Enter a phone number in the form (555) 555-5555:\n";
cin.getline( p, SIZE1 );
// pick apart the area code from the entire string
areaCode = strtok( p, "()" );
// function strtok to take the next token in the string
tokenPtr = strtok( 0, "-" );
// copies the result from the second call to strtok into phoneNumber
strcpy( phoneNumber, tokenPtr );
// the last call to strtok to take the last 4 digits
tokenPtr = strtok( 0, "" );
// concatenate the result with the current phoneNumber
strcat( phoneNumber, tokenPtr );
phone = phoneNumber;
cout << "\nThe area code is " << areaCode
<< "\nThe phone number is " << phone << endl;
return 0; // indicates successful termination
} // end main
```
Enter a phone number in the form (555) 555-5555:
(555) 429-4195
The area code is 555
The phone number is 4294195
You might also like to view...
A(n) ____________________ is a network of robot, or zombie, computers, which can harness their collective power to do considerable damage or send out huge amounts of junk e-mail.
Fill in the blank(s) with the appropriate word(s).
Why should a threads package be interested in the events of a thread’s becoming blocked or unblocked? Why should it be interested in the event of a virtual processor’s impending preemption? (Hint: other virtual processors may continue to be allocated.)
What will be an ideal response?
You cannot modify the Standard calendar to identify holidays or other nonworking days or times in which work should not be scheduled.
Answer the following statement true (T) or false (F)
FIGURE WIN 1-1
In Figure WIN 1-1 above, #3 is pointing to ____ buttons.
A. taskbar B. start bar C. status bar D. menu bar