Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strtok multiple delimeter question 1

Status
Not open for further replies.

pirigyi

Technical User
Apr 26, 2001
11
US
I'm trying to write a program that does the following:

* Ability to enter in phone numbers using a sentinel-controlled while loop.
* The loop will end when the user keys in -1 (or something).

THE PART I CANNOT FIGURE OUT:

I need to divide a phone number into 3 tokens using strtok. I do not have a problem doing this if the delimeter is the same, but it's not. The phone # is in the following format: '(999) 555-1212'. So the delimeters would be a " " a "-" and probably the remainder... I'm just not sure how to go about setting this up. Any help would be appreciated!

Thanks!
Pirigyi

 
#include <iostream>
#include <string>

int main()
{
char sPhoneNum[] = &quot;(999) 555-1212&quot;;
char *p = 0;

p = strtok( sPhoneNum,&quot; -&quot; );
std::cout << p <<
std::endl;

do {

p = strtok( NULL,&quot; -&quot; );

if ( p )
std::cout << p <<
std::endl;

} while ( p );

return 0;

} Mike L.G.
mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top