I am writing a program in C to separate the hour and minutes using arrays. However, the program gives me some outputs which exceed the length of the defined array. Can someone explain to me? I want the two array only include hour and the rest of the time without (AM/PM).
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main() {
char* s = (char *)malloc(10 * sizeof(char));
s="11:22:33AM";
printf("The time is %s\n",s);
char Hour[2];
char Minutes[6];
int i;
printf("The hour is %s\n",Hour);
printf("The minute is %s\n",Minutes);
for (i=0;i<2;i++){
Hour[i]=s[i];
}
for (i=2;i<8;i++){
Minutes[i-2]=s[i];
}
printf("%d\n",sizeof(Hour));
printf("%d\n",sizeof(Minutes));
printf("The hour is %s\n",Hour);
printf("The minute is %s\n",Minutes);
}