花一点时间给出hh:mm:ss,得到小时分钟和秒作为int

时间:2022-06-05 21:31:05

I have tried using:

我试过用过:

scanf("%d %d %d", &hour, &min, &sec);
printf("%d %d %d", hour, min, sec);

but it does not work, I think I have to bypass the ":" but am unsure how to do this.

但它不起作用,我想我必须绕过“:”但我不确定如何做到这一点。

Cheers

干杯

1 个解决方案

#1


3  

Please try:

请尝试:

if (scanf("%d:%d:%d", &hour, &min, &sec) != 3)
    …error handling…

#1


3  

Please try:

请尝试:

if (scanf("%d:%d:%d", &hour, &min, &sec) != 3)
    …error handling…