Question

In: Computer Science

Write a function called tokenizeTelNum that inputs a telephone number as a string in the form...

Write a function called tokenizeTelNum that inputs a telephone number as a string in the form (555) 555-5555. The function should use the function strok to extract the area code as a token, the first three digits of the phone 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 function 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. This should be written in C and written as a FUNCTION named tokenizeTelNum that can be called later in main. You must input the telephone number from the user and use strok thank u

Solutions

Expert Solution

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

void tokenizeTelNum (char *c){
char *p;
char arr[3];
p = strtok (c,"-");
// converting token string to int
int num = (p[1]-48);
num = num * 10 + (p[2]-48);
num = num * 10 + (p[3]-48);
p = strtok (c,"-");
p = strtok (c,"-");
  
// converting phone string to int
long phone = (p[10]-48);
phone = phone * 10 + (p[11]-48);
phone = phone * 10 + (p[12]-48);
phone = phone * 10 + (p[13]-48);
  
printf("Toaken : %d\n",num);
printf("Phone : %ld\n",phone);
}
int main(){
int arr[100];
printf("Enter number");
scanf("%s",arr);
tokenizeTelNum(arr);
return 0;

}


Related Solutions

JAVA 1. Write an application that inputs a telephone number as a string in the form...
JAVA 1. Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone 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. Both the area code and the phone number should be printed....
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the...
(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...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone 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. Both the area code and the phone number should be...
write an application that inputs a telephone number as a stringin the form (555) 555_5555....
write an application that inputs a telephone number as a string in the form (555) 555_5555. the application should use string method split to extract the area code as a token. the first three digits of the phone 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. Both the area code and the phone number should be printed. Remember that...
Write a program that inputs a string that represents a binary number. The string can contain...
Write a program that inputs a string that represents a binary number. The string can contain only 0s and 1s and no other characters, not even spaces. Validate that the entered number meets these requirements. If it does not, display an error message. If it is a valid binary number, determine the number of 1s that it contains. If it has exactly two 1s, display "Accepted". Otherwise, display "Rejected". All input and output should be from the console. Examples of...
C programming Write a function called string in() that takes two string pointers as arguments. If...
C programming Write a function called string in() that takes two string pointers as arguments. If the second string is contained in the first string, have the function return the address at which the contained string begins. For instance, string in(“hats”, “at”) would return the address of the a in hats. Otherwise, have the function return the null pointer. Test the function in a complete program that uses a loop to provide input values for feeding to the function.
Write a function that inputs the, n, the number of random trials for a standard normal...
Write a function that inputs the, n, the number of random trials for a standard normal distribution and then generates an array of n random observations (ie generate a random sample of n observations from a N(0,1) distribution. Then have the function perform a simple t-test on the sample, testing the null hypothesis that is mean 0. Have the function return two things: the results of the ttest and another variable that is set to the string= “reject” if the...
c++ programming: Write a function called baseConverter(string number, int startBase, int endBase) in c++ which converts...
c++ programming: Write a function called baseConverter(string number, int startBase, int endBase) in c++ which converts any base(startBase) to another (endBase) by first converting the start base to decimal then to the end base. Do not use library. (bases 1-36 only)
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x_start and ending at x_end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equallength sub-intervals in which the interval from x_start to x_end should be divided. Here,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT