Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <conio.h>
- #define MAXSIZE 1000
- int checkValidNumber (char s[]) {
- char format[] = "DD-LDDDD.DD";
- int i;
- if (strlen(s) != strlen(format))
- return 0;
- for (i = 0; i < strlen(s); ++i) {
- if ((format[i] == 'D' && isdigit(s[i]))
- || (format[i] == 'L' && isalpha(s[i]))
- || (format[i] != 'L' && (s[i] == format[i]))) {
- if (i == 1) {
- if ((s[i-1] >= '2' || s[i-1] <= '3') && (s[i] <= '2' || s[i] >= '9')) {}
- else
- return 0;
- }
- } else
- return 0;
- }
- return 1;
- }
- int main () {
- char numberPlate[MAXSIZE];
- while (1) {
- printf("Enter the number plate: ");
- scanf("%s", numberPlate);
- if (checkValidNumber(numberPlate)) {
- printf("\n!!! Valid number plate !!!\n\n");
- } else {
- printf("\n!!! Invalid number plate !!!\n\n");
- }
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement