RE: [Dev-C++] need help on converting a phone number
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Mitchell, T. (HNA) <Tam...@hj...> - 2001-01-26 20:42:16
|
thanks a million
-----Original Message-----
From: ropbert d baugh [mailto:lon...@ju...]
Sent: Friday, January 26, 2001 3:31 PM
To: dev...@li...
Subject: Re: [Dev-C++] need help on converting a phone number
Here you go. You forgot on minor item. see below.
lonestar36
On Fri, 26 Jan 2001 11:41:00 -0500 "Mitchell, Tamra (HNA)" <
Tam...@hj... <mailto:Tam...@hj...> > writes:
The program should convert the area code to an int using atoi
convert the phone number to a long using atol. It does not work correctly.
Any suggestions?
Thanks
/* Tamra Mitchell
Phone Number program */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
char phoneNumber[15];
char *codePtr, *threePtr, *fourPtr, *local;
int areacode, i;
long number;
printf("Enter phone number in following format (555) 555-5555 \n");
gets(phoneNumber);
codePtr = strtok(phoneNumber, " ");
threePtr = strtok(NULL, "-");
fourPtr = strtok(NULL, "\0");
for(i=0; i < strlen(codePtr); i++)
{
if(codePtr[i] == '(')
codePtr[i] = ' ';
{
if(codePtr[i] == ')')
codePtr[i] = ' ';
}
}
// printf("\nArea Code: ", codePtr); // forgot to put in format
specifier
// printf("Local Exchange: ", threePtr);
// printf("Local Number: ", fourPtr);
printf("\nArea Code: %s ", codePtr);
printf("Local Exchange: %s ", threePtr);
printf("Local Number: %s \n", fourPtr);
local=strcat(threePtr, fourPtr);
areacode=atoi(codePtr);
number=atol(local);
system("PAUSE");
return 0;
}
Tamra Y. Mitchell
Heinz North America
Operating Systems Analyst
(412) 237-5232 Work
(412) 996-9078 Cell Phone
|