Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<windows.h>
- struct time_struct{
- int hour;
- int min;
- int sec;
- };
- struct time_struct setTime(struct time_struct newTime);
- void dispalyTime(struct time_struct dis);
- void delay();
- struct time_struct update(struct time_struct up);
- int main(){
- struct time_struct clock={0,0,0};
- // clock=setTime(clock);
- while(1){
- delay();
- clock=update(clock);
- if(clock.min==3) break;
- }
- dispalyTime(clock);
- return 0;
- }
- struct time_struct setTime(struct time_struct newTime){
- printf("Set time :");
- scanf("%d %d %d",& newTime.hour,&newTime.min,&newTime.sec);
- return newTime;
- }
- void dispalyTime(struct time_struct dis){
- printf("%d:%d:%d\n",dis.hour,dis.min,dis.sec);
- }
- void delay(){
- Sleep(1000);
- }
- struct time_struct update(struct time_struct up){
- up.sec +=1;
- if(up.sec==60){
- up.min+=1;
- up.sec=0;
- dispalyTime(up);
- if(up.min==60){
- up.hour+=1;
- up.min=0;
- if(up.hour==24)
- up.hour=0;
- }
- }
- return up;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement