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);
printf("Local Exchange: ", threePtr);
printf("Local Number: ", 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
|