Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as

ID: 3803982 • Letter: #

Question

(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the form (555) 555-5555. The program should use function strtok to extract the area code as a token, the first three digits of the telephone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. The program should convert the area-code string to int and convert the phone-number string to long. Both the area code and the phone number should be printed

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
   int area_Code;
   long _phone;
   char phoneNumber[10];
  
   char telephone[]="(555) 555-5555 ";

   area_Code=atoi(strtok(telephone,"()"));//strtok to extract the area code and atoi convert string to int

   strcpy(phoneNumber, strtok(NULL,"-"));//first three digits and 5 digits of phone number
   strcat(phoneNumber, strtok(NULL," "));

   _phone=atol(phoneNumber);
   printf("The Area Code is %d ", area_Code);
   printf("The PhoneNumber is %ld ",_phone);
return 0;
}