Hi,
The problem is input the phone string, break it into tokens,take area code convert it into int,append the remaining (3+4)strings ,convert into long int and display the area code and phonenumber.
Well,my problem is for the remaining strings (ie.phone num) the ouput is 0 when converted to long int.Please tell me where I am going wrong!!
Help ,I am just frustrated ..such small thing is now becoming a big stuff for me........
Code:#include <cstring> #include <iostream> using namespace std; int main() { char phone[15]; char area[7]; char num[10]; char* tokenPtr; int areaCode; long int pnum; cout << "Enter a phone number [(###) ###-####]: "; cin.getline(phone, 15); while(tokenPtr!=NULL) { tokenPtr = strtok(phone, "()- "); //for tokenising the phonenum. strcpy(area,tokenPtr); //copy the first part into area areaCode = atoi(area);//converting strign to integer strcat(num, tokenPtr);//appending the remaining strings to num tokenPtr = strtok(NULL, "()- "); } cout << areaCode << atol(num) << endl; return 0; }



LinkBack URL
About LinkBacks


