TimeDiffs.c

来源:互联网 发布:先知者软件下载 编辑:程序博客网 时间:2024/05/16 14:03

#include<stdio.h>
typedef struct time{
int hour;
int minute;
int second;
}Time;
Time Enter(Time p);
Time Diffs(Time first,Time end);
main(){
Time first,end,diffs;
first=Enter(first);
end=Enter(end);
diffs=Diffs(first,end);
printf("Diffs:%dh%dm%ds",diffs.hour,diffs.minute,diffs.second);
}
Time Enter(Time p){ //怎样通过调用结构体指针一次完成对first,end的赋值?
puts("Enter  time:");
scanf("%d%*c%d%*c%d",&p.hour,&p.minute,&p.second);
return p;
}
Time Diffs(Time first,Time end){
Time diffs;
if(end.second<first.second){
end.second+=60;
end.minute-=1;
}
diffs.second=end.second-first.second;
if(end.minute<first.minute){
end.minute+=60;
end.hour-=1;
}
diffs.minute=end.minute-first.minute;
diffs.hour=end.hour-first.hour;
return diffs;
}





0 0
原创粉丝点击