#include<stdio.h> int HmsToS(int h, int m, int s) { int t; t=60*60*h+60*m+s; return t; } void PrintTime(int s) { int h=0,m=0; while(s>=60) { if(s>=3600) { h++; s=s-3600; } if(s<3600 && s>=60) { m++; s=s-60; } } printf("%02d:%02d:%02d\n",h,m,s); } int main() { int h,m,s,t,h1,m1,s1; while(scanf("%d:%d:%d\n",&h,&m,&s),!=EOF); { scanf("%d:%d:%d",&h1,&m1,&s1); t=HmsToS(h1,m1,s1)-HmsToS(h,m,s); PrintTime(t); } return 0; }为什么没有东西输出,请你帮我修改一个
时间: 2024-01-18 22:03:22 浏览: 28
您的代码中有一个多余的分号,导致程序无法正常读取输入。另外,注意在使用scanf时应该加上&符号,正确读取变量的地址。
下面是修改后的代码:
```
#include<stdio.h>
int HmsToS(int h, int m, int s) {
int t;
t=60*60*h+60*m+s;
return t;
}
void PrintTime(int s) {
int h=0,m=0;
while(s>=60)
{
if(s>=3600)
{
h++;
s=s-3600;
}
if(s<3600 && s>=60)
{
m++;
s=s-60;
}
}
printf("%02d:%02d:%02d\n",h,m,s);
}
int main() {
int h,m,s,t,h1,m1,s1;
while(scanf("%d:%d:%d",&h,&m,&s)!=EOF)
{
scanf("%d:%d:%d",&h1,&m1,&s1);
t=HmsToS(h1,m1,s1)-HmsToS(h,m,s);
PrintTime(t);
}
return 0;
}
```
注意,scanf("%d:%d:%d\n",&h,&m,&s)这样的写法是错误的,因为回车符不属于整数,需要去掉。