结构体实现模拟时钟
2015-11-15 17:16
288 查看
#include <stdio.h> typedef struct clock { int hour,minute,second; }CLOCK; //函数功能:时分秒时间的更新 void Update(CLOCK *t) { t->second++; if (t->second == 60) { t->second=0; t->minute++; /* code */ } if (t->minute ==60) { t->minute = 0; t->hour++; /* code */ } if (t->hour == 24) { t->hour=0; /* code */ } } //函数功能:时、分、秒时间的显示; void Display(CLOCK *t) { printf("%2d:%2d:%2d\n",t->hour,t->minute,t->second); } //函数功能:模拟延迟1s的时间 void Delay(void) { long t; for (t = 0; t<50000000 ; ++t) { /* code */ } } int main() { CLOCK myclock; myclock.hour=myclock.minute=myclock.second=0; for (long i = 0; i < 100000; ++i) { Update(&myclock); Display(&myclock); Delay(); /* code */ } return 0; }
相关文章推荐
- Linux 部署tomcat-实战操作
- 在QtCreator上 使用版本控制系统Git ---- 注意事项!
- 线索二叉树(先序,中序,后序)
- VC和MATLAB混合开发经验总结
- 野人学Android第二弹——Handler与Thread之间的关系
- 关于NSString的练习题
- 嵌套的向量式中断控制器(NVIC)
- 项目冲刺--第九天
- 自定义控件(18)---自定义控件之面板思想---addRule
- sql之left join、right join、inner join的区别
- 条件随机场
- Oracle 12c安装步骤及使用问题总结:
- ajax 的简述与原理
- 设计模式之单例模式
- Django 框架图
- JAVA--线程
- HIT2813 Garden visiting【组合数】
- IOS Objective c 异步链接 网上下载内容到本地及SBjson解析
- linux下mysql命令大全
- ubuntu15.04 安装mongodb