C语言实现电子时钟程序

所属分类: 软件编程 / C 语言 阅读数: 41
收藏 0 赞 0 分享

本文实例为大家分享了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语言非递归后序遍历二叉树,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

C语言单链表实现多项式相加

这篇文章主要为大家详细介绍了C语言单链表实现多项式相加,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

C语言二叉排序(搜索)树实例

这篇文章主要为大家详细介绍了C语言二叉排序树实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

NDK 数据结构之队列与栈等的实现

这篇文章主要介绍了NDK 数据结构之队列与栈等的实现的相关资料,希望通过本文大家能理解掌握这部分内容,需要的朋友可以参考下
收藏 0 赞 0 分享

C/C++经典实例之模拟计算器示例代码

最近在看到的一个需求,本以为比较简单,但花了不少时间,所以下面这篇文章主要给大家介绍了关于C/C++经典实例之模拟计算器的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
收藏 0 赞 0 分享

C语言中的getchar和putchar的使用方法

这篇文章主要介绍了C语言中的getchar和putchar的使用方法的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
收藏 0 赞 0 分享

C++实现洗牌发牌排序功能的示例代码

本篇文章主要介绍了C++实现洗牌发牌排序功能的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

C++计算图任意两点间的所有路径

这篇文章主要为大家详细介绍了C++求图任意两点间的所有路径 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

zlib库压缩和解压字符串STL string的实例详解

这篇文章主要介绍了zlib库压缩和解压字符串STL string的实例详解的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
收藏 0 赞 0 分享

C/C++ 获取Windows系统的位数32位或64位的实现代码

这篇文章主要介绍了C/C++ 获取Windows系统的位数32位或64位的实现代码的相关资料,希望通过本文能帮助到大家,让大家实现这样的功能,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多