C語言實(shí)現(xiàn)電子時(shí)鐘程序
更新時(shí)間:2022年03月31日 16:11:28 作者:Yan_Less
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)電子時(shí)鐘程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了C語言實(shí)現(xiàn)電子時(shí)鐘程序的具體代碼,供大家參考,具體內(nèi)容如下
Qt 里面運(yùn)行
#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); /* 設(shè)置背景顏色*/
textcolor(RED); /* 設(shè)置數(shù)字顯示顏色*/
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;
}以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++基于蔡基姆拉爾森計(jì)算公式實(shí)現(xiàn)由年月日確定周幾的方法示例
這篇文章主要介紹了C++基于蔡基姆拉爾森計(jì)算公式實(shí)現(xiàn)由年月日確定周幾的方法,涉及C++針對日期時(shí)間的數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-07-07
udp socket客戶端和udp服務(wù)端程序示例分享
這篇文章主要介紹了udp socket客戶端和udp服務(wù)端程序示例,需要的朋友可以參考下2014-03-03
C++?Opencv實(shí)現(xiàn)錄制九宮格視頻
這篇文章主要為大家介紹了如何利用C++和OpenCV庫實(shí)現(xiàn)錄制九宮格視頻,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)OpenCV有一定幫助,感興趣的可以了解一下2022-05-05
詳解Matlab繪制3D玫瑰花的方法(內(nèi)附旋轉(zhuǎn)版本)
這篇文章主要為大家介紹了如何利用Matlab繪制3D版的玫瑰花以及旋轉(zhuǎn)版的3D玫瑰花,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以動(dòng)手試一試2022-03-03
Visual Studio 2022最新版安裝教程(圖文詳解)
本文主要介紹了Visual Studio 2022最新版安裝教程,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
數(shù)據(jù)結(jié)構(gòu)之帶頭結(jié)點(diǎn)的單鏈表
單鏈表是一種鏈?zhǔn)酱嫒〉臄?shù)據(jù)結(jié)構(gòu),用一組地址任意的存儲(chǔ)單元存放線性表中的數(shù)據(jù)元素。鏈表中的數(shù)據(jù)是以結(jié)點(diǎn)來表示的,每個(gè)結(jié)點(diǎn)的構(gòu)成:數(shù)據(jù)域(數(shù)據(jù)元素的映象)?+?指針域(指示后繼元素存儲(chǔ)位置),元素就是存儲(chǔ)數(shù)據(jù)的存儲(chǔ)單元,指針就是連接每個(gè)結(jié)點(diǎn)的地址數(shù)據(jù)2023-07-07

