Im having trouble creating a code on C that after letting the user input a date it determines if the date is in a valid 24 hour format, any help would be greatly appreciated. Here's my code.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
bool format_correct(char format[]);
int looper;
char hour[] = "11:11";
int main()
{
while (looper == 1);{
printf("insert time in format HH:MM\n");
scanf("%s", &hour);
if ((hour < 25) && format_correct(hour)){
printf("%s is a correct hour",hour);
looper ++;
}
else
printf("incorrect format, introduce time in format HH:MM \n");
return 0;
}
}
bool format_correct(char format[])
{
if (strlen(format) != 5) return false;
if (!isdigit(format[0])) return false;
if (!isdigit(format[1])) return false;
if (format[2] != ":") return false;
if (!isdigit(format[3])) return false;
if (!isdigit(format[4])) return false;
}