Problem Description:
China's mainland operators of mobile phone number standard format is: Country code + mobile phone number, for example: 8613912345678. Features are as follows:
1, 13 bits in length;
2, with 86 of the country code starts;
3, mobile phone number of each person is a number.
Please implement the function requirements of mobile phone number legality judgment:
1) If the mobile phone number is valid, return 0;
2) If the phone number is not valid, return 1
3) If the phone number contains non-numeric characters, return 2;
4) If the mobile phone number does not begin with 86, return 3;
"Note" In addition to the success of the case, the above other legal judgment priority reduced. That is to say, if the length is not valid, return 1 directly, do not need to do other legal judgment.
Required implementation functions:
int verifymsisdn (char* inmsisdn)
"Input" char* inmsisdn, which represents the input mobile number string.
"Output" none
The result of the "return" judgment, type int
The C code is as follows:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define LEN 13#define SIZE 100int VERIFYMSISDN (char* inmsisdn); int main () {char *str = (char*) malloc (size*sizeof (char));p rintf ("Please input the Cellphone number: "); scanf ("%s ", str);p rintf (" The result is%d\n ", verifymsisdn (str)); return 0;} int verifymsisdn (char* inmsisdn) {int flag = 0;if (LEN = = strlen (inmsisdn)) {if (*inmsisdn = = ' 8 ' && * (inmsisdn+1) = = ' 6 ') flag = 1;while (*inmsisdn! = ') {if (*inmsisdn >= ' 0 ' && *inmsisdn <= ' 9 ') Inmsisdn++;elsereturn 2;} if (flag = = 1) return 0;elsereturn 3;} Elsereturn 1;}
Several test cases are used: