Question

Please help me to write a program to check telephone number validity . (just check all...

Please help me to write a program to check telephone number validity . (just check all characters are "0"~"9")
1.C language
2.Please use "printf"(no scanf、gets....)
3.only argv ,argc accepted
4.Please explain the steps (cause I'm a beginner hhhhh)
Thank you soooooo much!!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*

To check a valid phone number we need to check digits, length, country code and starting digit of phone number.

But in your case you need to check only whether It contains all digits or not.

So to check this you can follow below simple simple steps
1. Declare a boolean variable and assigne true value to it.
2. Iterate over each character of the input
3. Check if current character in 0 to 9 character range
4. If all are digits then correct otherwise incorrect.

As your question instructed that we can not use any function other than printf so we need to use command line arguments.

argc: refers to the number of arguments passed by the user including the name of the program.
argv[]: is a pointer array which points to each argument passed to the program

argv[0]: name of the program
argv[1]: First argument to the program

Sample Input:
9090909

Sample Output:
The argument supplied is 9090909
Valid phone nnumber


*/

/**************************Execution Steps**********************************************
1. Copy the code from below #include<sdtio.h> till last to the you ide/editor
2. Save the code as Telecomvalidation.c
3. Compile the code using command gcc Telecomvalidation.c
4. Run the program using command ./Telecomvalidation 909840945
  
If still not clear, Please ask you friend or search on google "How to execute c program in linux"
  
*/

/***************Your program start from below line******************************/

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

int main( int argc, char *argv[] ) {

int i,len,flag=0;
//you can change the size of array based on length of telephone no
char telphno[10];
printf("Program name : %s\n", argv[0]);

if( argc == 2 ) {
printf("The argument supplied is %s\n", argv[1]);
//Getting the length of the phone number
len=strlen(argv[1]);
  
//copying first argument to the new variable telphno
strcpy(telphno,argv[1]);
  
//Iterating over each character and checking whther a character is in the range of character 0 to 9
//If in range then continue else updating flag value and breaking the loop
for(i=0;i<len;i++)
{
if(telphno[i]<'0' || telphno[i]>'9')
{
flag=1;
break;
}
}
//Printing the output.
if(flag==1)
printf("Invalid phone nnumber\n");
else
printf("Valid phone nnumber\n");
}
else if( argc > 2 ) {
printf("Too many arguments supplied.\n");
}
else {
printf("One argument expected.\n");
}
}

Add a comment
Know the answer?
Add Answer to:
Please help me to write a program to check telephone number validity . (just check all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me write down a program to check email address valid or not. Tip:parse the...

    Please help me write down a program to check email address valid or not. Tip:parse the string and count the special characters like '@', '.' .and at least one character. Suggested libc functions: printf() 1.Have to be by the argc/argv of main function 2.Connot use scanf/getchar and other user input functions 3.Please explain the details and steps for me cause I'm a beginner hhhhhh Thank you soooo much for helping me!

  • Please help run all the examples correctly and only the examples without extra things in or...

    Please help run all the examples correctly and only the examples without extra things in or less things in, it should run EXACTLY 100% like the examples. C language ONLY. And please dont reply if you cant run all the examples given. We know the tr command allows you to replace or translate characters in of a stream. It takes in two arguments - a set of characters to be replaced and a set of replacement characters. The full functionality...

  • Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write...

    Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write a program to ask the user for a number that includes a decimal point. Then display the integer part of the number (the part of the number to the left of the decimal point) and the decimal part of the number (the part of the number to the right of the decimal point, including the decimal point Follow the 3 steps in the Information...

  • Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will...

    Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will...

  • Write a program in C to generate random numbers. The program recieves 4 items on activation...

    Write a program in C to generate random numbers. The program recieves 4 items on activation through argv: 1. Name of the data file 2. Number of items for program to generate 3. Range of numbers 4. Seed of the random number generator Example run: ./rand datafile.txt 20 1000 3127 Program must convert all numbers to ints using atoi(), must save all parameters into variables, opens the data file to write the random numbers into it, program loops to generate...

  • Could you please help me with an answer to this question in a simple way for...

    Could you please help me with an answer to this question in a simple way for the beginner? This is a beginner level class so can you please help me. The code must have beginner level implementation. Can you also please explain what things do. Thank you! Write a program that prompts the user for a positive integer number smaller than 256 (i.e. in [0...255]) and converts it into an 8-bit binary number. The bits are the remainders of the...

  • [3] In python, please help me write the functions needed for this problem: Another Way to do Parentheses: For this probl...

    [3] In python, please help me write the functions needed for this problem: Another Way to do Parentheses: For this problem, you will be given a string that contains parentheses, brackets, and curly braces ( (, ), [, ], {,} ) and other characters. As a human you are given a string of any characters, determine if the parentheses, brackets, and braces match. (No trailing or leading parentheses). The function called on an empty string will return True. Parentheses must...

  • Please help with this. Modify the program Figure 2.6 (exam1/exam2). Ask the user to enter two...

    Please help with this. Modify the program Figure 2.6 (exam1/exam2). Ask the user to enter two numbers Find the result when the first number is divided by the second Also find the remainder when the first number is divided by the second In other words, the program used to do this: 68 85 score = 81 Now it should do this 22 2 Divide = 11 Remainder = 0 If you run it again: 11 2 Divide = 5 Remainder...

  • Can somebody please help me solve and understand this problem.. please Just to be clear, bc...

    Can somebody please help me solve and understand this problem.. please Just to be clear, bc i know its blurry the numbers are 8 and -8 Thank you so much Write legibly, explain your steps/solutions. Your solutions are limited to this sheet only (fro Question 1 (40pts) Find the DTFT of the following signal, simplify as much as you can. rIn] 6 o- =1 -3 -2-1 01 2 34 s

  • Write a complete C program that inputs a paragraph of text and prints out each unique...

    Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT