Write a program that input a telephone number as a string in the form" (677) 555_-9879 "the program should use function strtok to extract the area code as atoken ,the first three digits of the phone number as atokken ,and the last four number of the phone number as atokens ,the seven digit of the phone number should be conatenated into one string . the program should convert the area code string to int and convert the phone number string to long
سؤال يئرقني كثيرا
مغلق
السلام عليكم,
هذا البرنامج سيقوم إن شاء الله بالمطلوب . ندخل الرقم على الشكل الذي ذكرت ويمكن أيضا أن نستعمل فراغا بين الأرقام . مثلا الرقم : (546) - 4581 -652 85 أو غيره وفي النتيجة يعطينا سترينغ يكون فيه الأرقام فقط . وقد استعملت في Delimiters الأحرف التالية : فراغ - ( ) وإذا أردت يمكن أن تزيد ما تريد مثل _ أو غيره.
وهذا هو الكود ب س++ :
#include <string.h>
#include <iostream.h>
void main()
{
char mystr[30];
char delimiter[] = "( )-";
char *token;
char Result[30];
cin.getline(mystr,30);
token = strtok( mystr, delimiter );
strcpy(Result,token);
while( token != NULL )
{
token = strtok( NULL, delimiter );
if (token)
strcat(Result,token);
}
cout << Result <<"\n";
}إلى اللقاء.
هذا الموضوع مغلق.