الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال يئرقني كثيرا

مغلق
بدأه رائد الظفيري في 7 يوليو 2004 · 1 رد · 458 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

#2

السلام عليكم,

هذا البرنامج سيقوم إن شاء الله بالمطلوب . ندخل الرقم على الشكل الذي ذكرت ويمكن أيضا أن نستعمل فراغا بين الأرقام . مثلا الرقم : (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";

}

إلى اللقاء.

هذا الموضوع مغلق.

مواضيع مشابهة