Advertisement
pdaogu

HW13.3

Nov 27th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <conio.h>
  5.  
  6. #define MAXSIZE 1000
  7.  
  8. int checkValidNumber (char s[]) {
  9.     char format[] = "DD-LDDDD.DD";
  10.     int i;
  11.     if (strlen(s) != strlen(format))
  12.         return 0;
  13.     for (i = 0; i < strlen(s); ++i) {
  14.         if ((format[i] == 'D' && isdigit(s[i]))
  15.             || (format[i] == 'L' && isalpha(s[i]))
  16.             || (format[i] != 'L' && (s[i] == format[i]))) {
  17.             if (i == 1) {
  18.                 if ((s[i-1] >= '2' || s[i-1] <= '3') && (s[i] <= '2' || s[i] >= '9')) {}
  19.                 else
  20.                     return 0;
  21.             }
  22.         } else
  23.             return 0;
  24.     }
  25.     return 1;
  26. }
  27.  
  28. int main () {
  29.     char numberPlate[MAXSIZE];
  30.     while (1) {
  31.         printf("Enter the number plate: ");
  32.         scanf("%s", numberPlate);
  33.         if (checkValidNumber(numberPlate)) {
  34.             printf("\n!!! Valid number plate !!!\n\n");
  35.         } else {
  36.             printf("\n!!! Invalid number plate !!!\n\n");
  37.         }
  38.     }
  39.     getch();
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement