时钟c语言自动同步,c语言——做一个简单的计时器/时钟

闲来无事看到桌面右下角的时钟,就想仿照做一个数字时钟,小白在此,仅供消遣,大神勿喷O(∩_∩)O~

#include

#include

#include

#include

#include

int h,m,s,e,d=0;

void updata();

void display();

void delay();

void gotoxy(int x,int y);

void gotoxy(int x,int y) //将光标移动到坐标为(x,y)的地方

{

CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

HANDLE hConsoleOut;

hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);

GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);

csbiInfo.dwCursorPosition.X = x;

csbiInfo.dwCursorPosition.Y = y;

SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);

}

/*这是功能实现的关键,必须要能在同一个位置显示才行( ⊙ o ⊙ )啊~*/

void updata() //更新秒、分、时

{

if (s==60)

{

s=0;

m++;

}

if (m==60)

{

m=0;

h++;

}

if (h==24)

{

h=0;

d++;

exit (0);

}

}

void delay()

/*这里就是控制更新时间间隔为1s啦,考虑整个程序运行的时间,最后感觉sleep(9)误差小一些即延迟900ms,童鞋也可自测(*^__^*) 嘻嘻……*/

{

int i;

int j;

for(i=0;i<=100;i++)

{

Sleep(9);

//for(j=0;j<10000000;j++);

switch(i/10)

{

case 0 : printf("\b\b\b0%d)",i);break;

case 1 :

case 2 :

case 3 :

case 4 :

case 5 :

case 6 :

case 7 :

case 8 :

case 9 :printf("\b\b\b%d)",i);break;

case 10:printf("\b\b\b00)");s++;break;

}

}

printf("\n\t\t╠点击屏幕暂停,按任意键继续\t\t\t ╣");

printf("\n\t\t╚─────────────────────────╝");

}

void display() //显示时间

{

gotoxy(18,3); //成败在此一举~~~~

if(h<10) printf("\t\t 0%d\:",h);

else printf("\n\t\t╠\t\t%d\:",h);

if(m<10) printf("0%d\:",m);

else printf("%d\:",m);

if(s<10) printf("0%d",s);

else printf("%d",s);

printf("(00)");

}

int main(void)

{

printf("\t\t╔┄┄┄┄┄┄┄┄┄*****计时器*****┄┄┄┄┄┄┄┄╗");

printf("\n\t\t╠**************************************************╣");

printf("\n\t\t╠时间输入:(时 分 秒) ╣");

printf("\n\t\t╠ ╣");

gotoxy(18,3);

scanf("%d%d%d",&h,&m,&s);

while(1)

{

display();

delay();

updata();

}

return 0;

}

okay~小小地兴奋一下下,弄外面这个框框真的很费神啊╮(╯╰)╭

那就到此结束啦,给自己立个flag,继续学习,有朝一日再来喷自己~~(^ω^)

打开App,阅读手记

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值