Advertisement
Guest User

example

a guest
Dec 10th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. main()
  5. {
  6.  
  7.     int isIncorrect = 1;
  8.  
  9.     do {
  10.        char fullTime[6];
  11.        scanf("%s",fullTime);
  12.  
  13.        // check time format
  14.        if( fullTime[5]!='\0') {
  15.            printf("Too many characters!");
  16.        }
  17.        else if (fullTime[2] != ':') {
  18.            printf("Wrong format!");
  19.        }
  20.        else if( !(isdigit(fullTime[0]) && isdigit(fullTime[1]) && isdigit(fullTime[3]) && isdigit(fullTime[4]) ) ) {
  21.            printf("Not a number!");
  22.        }
  23.        else {
  24.            printf("%s",fullTime);
  25.            isIncorrect=0;
  26.        }
  27.        puts("");
  28.     }
  29.     while( isIncorrect );
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement