算法-字符输入向整数类型转换

#include 
#include 

int main() {
    char time_range[20];
    printf("请输入时间段(格式:HH:MM:SS - HH:MM:SS):");
    fgets(time_range, sizeof(time_range), stdin);

    char start_time[9], end_time[9];
    strncpy(start_time, time_range, 8);
    start_time[8] = '\0';
    strncpy(end_time, time_range + 11, 8);
    end_time[8] = '\0';

    printf("开始时间:%s\n", start_time);
    printf("结束时间:%s\n", end_time);
    int start_int;
    sscanf(start_time, "%2d", &start_int);
    printf("%d", start_int);
    return 0;
}

你可能感兴趣的:(算法,算法)