C语言实现电子时钟程序
更新时间:2020年4月25日 17:27 点击:2044
本文实例为大家分享了C语言实现电子时钟程序的具体代码,供大家参考,具体内容如下
Qt 里面运行
#include<windows.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> typedef struct { int x; int y; }Point; time_t now; struct tm *pt, t1, t2; int printpoint(Point p) { Point p1; p1.x = p.x + 2; p1.y = p.y + 4; gotoxy(p1.x, p1.y); printf("%c%c", 2, 2); gotoxy(p1.x, p1.y + 1); printf("%c%c", 2, 2); p1.y += 4; gotoxy(p1.x, p1.y); printf("%c%c", 2, 2); gotoxy(p1.x, p1.y + 1); printf("%c%c", 2, 2); return 0; } int print0(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else printf("%c%4s%c", 2, " ", 2); } return 0; } int print1(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); printf("%5s%c", " ", 2); } return 0; } int print2(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 6 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else if (i>0 && i<6) printf("%5s%c", " ", 2); else printf("%c", 2); } return 0; } int print3(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 6 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else printf("%5s%c", " ", 2); } return 0; } int print4(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i<6) printf("%c%4s%c", 2, " ", 2); else if (i == 6) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else printf("%5s%c", " ", 2); } return 0; } int print5(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 6 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else if (i>0 && i<6) printf("%c", 2); else printf("%5s%c", " ", 2); } return 0; } int print6(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 6 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else if (i>0 && i<6) printf("%c", 2); else printf("%c%4s%c", 2, " ", 2); } return 0; } int print7(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else printf("%5s%c", " ", 2); } return 0; } int print8(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 6 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else printf("%c%4s%c", 2, " ", 2); } return 0; } int print9(Point p) { int i = 0; for (; i<13; i++) { gotoxy(p.x + 1, p.y + i); if (i == 0 || i == 6 || i == 12) printf("%c%c%c%c%c%c", 2, 2, 2, 2, 2, 2); else if (i>0 && i<6) printf("%c%4s%c", 2, " ", 2); else printf("%5s%c", " ", 2); } return 0; } int clear(Point p) { int i = 0; for (; i<13; i++) gotoxy(p.x, p.y + i); printf("%16s", " "); return 0; } int printtime(Point p, int n) { int a, b; Point pp; a = n / 10, b = n % 10; pp.x = p.x + 8, pp.y = p.y; switch (a) { case 0: print0(p); break; case 1: print1(p); break; case 2: print2(p); break; case 3: print3(p); break; case 4: print4(p); break; case 5: print5(p); break; } switch (b) { case 0: print0(pp); break; case 1: print1(pp); break; case 2: print2(pp); break; case 3: print3(pp); break; case 4: print4(pp); break; case 5: print5(pp); break; case 6: print6(pp); break; case 7: print7(pp); break; case 8: print8(pp); break; case 9: print9(pp); break; } return 0; } int main() { Point phour, pmin, psec, point1, point2; phour.x = 9, pmin.x = 32, psec.x = 55; phour.y = pmin.y = psec.y = 7; point1.x = 25, point2.x = 49; point1.y = point2.y = 7; clrscr(); textbackground(YELLOW); /* 设置背景颜色*/ textcolor(RED); /* 设置数字显示颜色*/ now = time(0); pt = localtime(&now); t1 = *pt; printtime(phour, t1.tm_hour); printpoint(point1); printtime(pmin, t1.tm_min); printpoint(point2); printtime(psec, t1.tm_sec); while (1) { now = time(0); pt = localtime(&now); t2 = *pt; if (t2.tm_sec != t1.tm_sec) { t1 = t2; clrscr(); printtime(phour, t1.tm_hour); printpoint(point1); printtime(pmin, t1.tm_min); printpoint(point2); printtime(psec, t1.tm_sec); } if (bioskey(1) == 0) continue; else exit(0); } return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持猪先飞。
上一篇: 利用C语言解决八皇后问题以及解析
下一篇: 关于C语言中E-R图的详解
相关文章
- 这篇文章主要为大家详细介绍了C语言实现放烟花的程序,有音乐播放,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-23
- 本篇文章主要介绍C语言中char的知识,并附有代码实例,以便大家在学习的时候更好的理解,有需要的可以看一下...2020-04-25
- 这篇文章主要介绍了详解如何将c语言文件打包成exe可执行程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-25
- 华为手机怎么开启双时钟?华为手机是可以设置双时钟的,如果来回在两个有时差的地方工作,是可以设置双时钟显示,下面我们就来看看华为添加双时钟的技巧,需要的朋友可以参考下...2020-12-08
- free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
- 这篇文章主要介绍了C语言中计算正弦的相关函数总结,包括正弦和双曲线正弦以及反正弦的函数,需要的朋友可以参考下...2020-04-25
详解C语言中的rename()函数和remove()函数的使用方法
这篇文章主要介绍了详解C语言中的rename()函数和remove()函数的使用方法,是C语言入门学习中的基础知识,需要的朋友可以参考下...2020-04-25- 这篇文章主要介绍了C语言中求和、计算平均值、方差和标准差的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-12-10
- 本篇文章主要讲解C语言 基本语法,这里提供简单的示例和代码来详细讲解C语言的基本语法,开始学习C语言的朋友可以看一下,希望能够给你带来帮助...2021-09-18
- 这篇文章主要介绍了C语言中send()函数和sendto()函数的使用方法,是C语言入门学习中的基础知识,需要的朋友可以参考下...2020-04-25
- 今天小编就为大家分享一篇C语言实现从文件读入一个3*3数组,并计算每行的平均值,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-04-25
- 这篇文章主要为大家详细介绍了微信小程序入门之绘制时钟,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-10-23
- 这篇文章主要介绍了使用C语言操作文件的基本函数整理,包括创建和打开以及关闭文件的操作方法,需要的朋友可以参考下...2020-04-25
- 这篇文章主要介绍了C语言中memcpy 函数的用法详解的相关资料,需要的朋友可以参考下...2020-04-25
- 这篇文章主要介绍了C语言中查找字符在字符串中出现的位置的方法,分别是strchr()函数和strrchr()函数的使用,需要的朋友可以参考下...2020-04-25
- 很多同学在学习c语言的时候是不是会碰到a++和++a都有甚么作用啊。今天我们就来探讨下...2020-04-25
- 下面小编就为大家带来一篇C语言实现时间戳转日期的算法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-04-25
- 这篇文章主要对C语言中const关键字的用法进行了详细的分析介绍,需要的朋友可以参考下...2020-04-25
- 这篇文章主要介绍了C语言之整数划分问题(递归法)实例代码的相关资料,需要的朋友可以参考下...2020-04-25
- 本文给大家简单介绍下c实现linux下的数据库备份的方法和具体的源码,十分的实用,有需要的小伙伴可以参考下。...2020-04-25