I've begun, but I've run into trouble.
Code: Select all
// Lab 8.35.cpp : main project file.
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using namespace System;
int main()
{
char areaCode[6];
char number[9];
// char lastNumbers[5];
cout << "Please enter a phone number in the format (xxx) xxx-xxxx" << endl;
cin >> areaCode >> number;
char *ptrToken;
char *ptrToken2;
char *ptrToken3;
ptrToken = strtok( areaCode, " " );
ptrToken2 = strtok( number, " ,.-");
ptrToken3 = strtok (number, " ");
while(ptrToken != NULL && ptrToken2 != " ")
{
cout << ptrToken << "\n";
ptrToken = strtok(NULL, " ");
cout << ptrToken2 << "\n";
ptrToken2 = strtok(NULL, " ");
cout << ptrToken3 << "\n";
ptrToken3 = strtok(NULL, " ");
}
cout << "\nAfter strtok, the number = " << areaCode << number << endl;
system("pause");
}
Code: Select all
Please enter a phone number in the format (xxx) xxx-xxxx.
(999) 999-9999 < Input
(999)
999
999
After strtok, the number = (999)999