C语言环境下,实时时间的显示!

960阅读 0评论2011-06-26 awool_cu
分类:C/C++

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <system.h>
  4. #include <time.h>

  5. /*==================================
  6. 功能描述:打印出系统当前的实时时间
  7. 所用函数:ctime_print()
  8. 返回值: 有,返回当前系统时间
  9. ==================================*/

  10. main()
  11. {
  12.     time_t t=0;
  13.     const char *ctime_print(time_t value); /* 声明时间处理函数 */

  14.     printf("The currnet time is : %s\n",ctime_print(t));
  15.     sleep(5); /* 系统睡眠5秒 */
  16.     printf("The current time after 5 seconds is : %s\n",ctime_print(t));
  17.     getch();
  18. }

  19. const char *ctime_print(time_t value) /* 时间处理函数 */
  20. {
  21.     static char buf[32];
  22.     char *p;

  23.     time(&value);
  24.     strcpy(buf, ctime(&value));


  25.     if ((p = strchr(buf, '\n')) != NULL)
  26.         *p = '\0';

  27.     return buf;
  28. }
上一篇:字符串倒序显示!
下一篇:一个函数计算1-2+3-4+5-6+7......+n 的值