这是我的小片段 产生断裂断裂断层
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int checkTiime(char time[]);
int main(int argc, char** argv) {
char time1[6];
char time2[6];
printf("Tempo 1 [hh:mm]: ");
fgets(time1, sizeof time1, stdin);
printf("Tempo 2 [hh:mm]: ");
fgets(time2, sizeof time2, stdin);
printf("Checktime: %d", checkTime(time1));
return (EXIT_SUCCESS);
}
int checkTime(char time[]){
long hours = 0;
long minutes = 0;
if(time[2] == : ) {
if(isdigit(time[3]) && isdigit(time[4]) && isdigit(time[0]) && isdigit(time[1])) {
hours = strtol(time[0], NULL, 10) + strtol(time[1], NULL, 10);
minutes = strtol(time[3], NULL, 10) + strtol(time[4], NULL, 10);
if((hours >= 0 && hours <= 23) && (minutes >= 0 && minutes <= 59)){
return 0;
} else {
return 1;
}
} else {
return 1;
}
} else {
return 1;
}
}
谁能帮我 我真的不知道为什么给我带来麻烦
我还注意到,例如,当我输入“12: 34”时,它要求我输入第二个输入,但是当我写“12: 34”时,然后我用后空格删除“34”,再输入“34”,它写第二个打印页f,但不允许我输入第二个输入以及程序出口。
<强度>个人评论: 强度>
I noticed that it s better to use gets()
function to input strings beacause it doesn t count the
character.