C语言编写时钟程序,,急急急急急急!!!!

本人急需一个用C语言编写的C程序。请大家帮忙了。复制的也可以,网上下的也可以,能编译,运行就好了。谢了。还有问题请留言!!!谁能帮忙不胜感激!
运行的环境VC++6.0

第1个回答  2009-09-26
刚做好一个,功能比较简单(年,月,日,时,分,秒).喜欢的拿去用:

#include "stdio.h"
#include "time.h"
#include "dos.h"
#include "windows.h"
#include "string.h"
#include "ctype.h"

int year_r(); //显示年
int month_h(); //月
int date_e(); //日
int time_e(); //时间
char * time_ta(); //将日期时间转换成字符串
int wait_t(); //延时1秒

char * time_ta() //将日期时间转换成字符串
{
char *q;
time_t t;
t=time(NULL);
q=ctime(&t);
//printf("*q_address = 0x%x\n",q);
return (q);
}

int wait_t() //延时1秒
{
long temp_total=0;
time_t time_temp;
time_temp=time(NULL);
temp_total=time_temp;
for(;;)
{
time_temp=time(NULL);
if(abs(time_temp - temp_total) >=1)
break;
}

return (0);
}

int main()
{
int temp;

system("cls"); //清屏
printf("\n\n\n\n\n\n\n\n\t\t\t");
year_r();
printf("年");
temp = month_h();
if (temp != 13)
{
printf("%d",temp);
printf("月");
}
else printf("month error!\n");
date_e();
printf("日");
time_e();
printf("\r");
for(;;) //显示年月日时分秒
{
wait_t(); // 1秒钟到显示年月日时分秒
system("cls");
printf("\n\n\n\n\n\n\n\n\t\t\t");
year_r();
printf("年");
temp = month_h();
if (temp != 13)
{
printf("%d",temp);
printf("月");
}
else printf("month error!\n");

date_e();
printf("日");
time_e();
}
getchar();

}

int year_r() //显示年
{

char *p;
int i;
p=time_ta();
for(i=0;i<24;i++,p++) //ctime函数返回字符为24个
if(i>19&&i<24)
printf("%c",*p);
return (0);
}

int month_h() //显示月
{
char month_n[12][5]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
char *p;
char month[4]; //存放三个字符
int i,j=0;
p=time_ta();
for(i=0;i<24;i++,p++) //i<24因为ctime()函数返回有24个字符
{
if(i>=4 && i<7) //取ctime函数返回值的第5--8共三个字符.
{
month[j++]=*p;
if(j==3)
{
month[j]='\0';
break;

}
}
}
for (i=0;i<12;i++)
{
if (strcmp(month_n[i],month) == 0)
{
return (i+1);

}

}

return (13);

}

int date_e() //日
{
int j=0,i=0;
char date[2];
char *p;
p=time_ta();
for(i=0;i<24;i++,p++)
if(i>=8&&i<10)
{ date[j]=*p;
printf("%c",date[j++]);}
return 0;
}

int time_e() //时间
{ int i;
char *p;
p=time_ta();
for(i=0;i<24;i++,p++)
if(i>10&&i<19)
printf("%c",*p);
printf("\n");
return (0);
}本回答被提问者采纳
第2个回答  2009-09-25
http://hi.baidu.com/fengaiguo/blog/item/842c570f6baad52f6059f3dd.html
地址

/********************************************************************

程序名称:用C语言编写的艺术时钟程序

功能描述: 运行程序后,会出现一个活动的时钟界面

所用函数:setwritemode(1); gettime(t);

编写日期:2006/X/X
修改日期:2008/4/8/20:31

注意事项:要修改Options>linker>Graphics library——改为On

/*******************************************************************/

#include<graphics.h>
#include<math.h>
#include<dos.h>
#define Pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*Pi/180-Pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*Pi/180-Pi/2)+240;
#define d(a,b,c) X(a,b,c); Y(a,b,c); line(300,240,x,y);
/******************* fun---init *************************/
void init()
{int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++)
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*Pi/180)+300;
y1=200*sin(i*6*Pi/180)+240;
x2=(200-l)*cos(i*6*Pi/180)+300;
y2=(200-l)*sin(i*6*Pi/180)+240;
line(x1,y1,x2,y2);
}
}
/***struct time{ h=t[0].ti_hour;m=t[0].ti_min;s=t [0].ti_sec;};******/

/*********** main **************************************************/
main()
{ int x,y;
int gdriver=DETECT,gmode;
unsigned char h,m,s;
struct time t[1];
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
setcolor(7); setlinestyle(0,0,3); d(130,h,30);
setcolor(14); setlinestyle(0,0,2); d(165,m,6);
setcolor(4); setlinestyle(0,0,1); d(190,s,6);
/********* while ******************************************************/
while(!kbhit())
{ while(t[0].ti_sec==s) gettime(t);
sound(400); delay(70); nosound();
setcolor(4); d(190,s,6);
s=t[0].ti_sec; d(190,s,6);

if(t[0].ti_min!=m)
{setcolor(14); d(170,m,4);
m=t[0].ti_min; d(170,m,4);
}
if(t[0].ti_hour!=h)
{setcolor(7); d(150,h,30);
h=t[0].ti_hour; d(150,h,30);
sound(1000); delay(140);
sound(2000); delay(240);
nosound();
}
}
getch();
closegraph();
}

/******************************************END*****************************/
第3个回答  2009-10-08
fgfgddgd

c语言怎么样编写一个时钟程序
c语言时钟程序代码如下:include<windows.h> include<math.h> define ID_TIMER 1\/\/计时器ID define TWOPI (2*3.14159)LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow){ static TCHAR szAppName[]=TEXT...

求一个关于用C语言编写的电子时钟的程序,内容要有闹钟,可以调整时间
uchar data CLOCK[4]={0,0,0,12};\/\/存放时钟时间(百分秒,秒,分,和时位)\/\/数码管显示表0-f 灭 uchar code TABLE[]={0xBE,0x06,0xEA,0x6E,0x56,0x7C,0xFC,0x0E,0xFE,0x7E,0x00};\/\/ \/\/模拟串口发送一个字节数据 函数 \/\/ void SendData(unsigned char senddata){ unsigned ...

单片机C语言该怎么编写时钟程序?
这个是简单的数码管时钟显示如果有需要,我写过比较完善的1602显示时钟.显示控制年月日等等.#include<reg51.h> sbit Begin=P2^0;sbit Hour=P2^1;sbit Mus=P2^2;sbit End=P2^3;unsigned char code Tab[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x...

用c语言编一个时钟程序实现时分秒计时功能
include int main(){ time_t t1,t2;struct tm *ptm;char timestr[128]={'\\0'};time(&t1);while(1){ time(&t2);if(difftime(t2,t1)>=1){ system("cls");ptm=localtime(&t2);strftime(timestr,128,"%H:%M:%S",ptm);printf("%s\\n",timestr);t1=t2;} } system("PAUSE");r...

怎么用C语言编程数字时钟
&graphmode,"C:\\\\TC2"); \/\/初始化VGA屏幕模式setbkcolor(BLACK); \/\/使用黑色的背景色while(!kbhit(0)) \/\/若有键盘输入,则跳出,即是结束程序{ setcolor(GREEN); \/\/把画笔设为绿色circle(mid_x,mid_y,180); \/\/钟的外圆circle(mid_x,mid_y,150); \/\/钟的内圆circle(mid_x,mid_y,...

谁能帮我编一个C语言时钟啊
\/*这是我做了一半的万年历的界面,正好有你需要的显示时钟的功能,你把它分离出来吧*\/ include<stdio.h> include<windows.h> include int week; \/\/用于存放星期几的变量 \/***定义结构体存时间数据***\/ int year,month,day,hour,min,sec; \/\/当前时间 int l_year,l_month,l_day,l_...

C语言程序设计题:模拟时钟转动的程序,怎么做?
turbo c 2.0模拟时钟转动程序代码*\/ #include"graphics.h" #include"math.h" #include"dos.h" #define pi 3.1415926 #define X(a,b,c) x=a*cos(b*c*pi\/180-pi\/2)+300 #define Y(a,b,c) y=a*sin(b*c*pi\/180-pi\/2)+240 #define d(a,b,c) X(a,b,c);Y(...

用C语言编数码管时钟程序
\/\/G, F A E B H C D sbit l1=P2^7;sbit l2=P2^6;sbit l3=P2^5;sbit l4=P2^4;sbit l5=P2^3;sbit l6=P2^2;sbit l7=P2^1;sbit l8=P2^0;sbit j1=P1^1;sbit j2=P1^2;unsigned char code ledcode[]={0x84,0xf5,0x46,0x54,0x35,0x1c,0x0c,0xd5...

c语言 倒计时时钟程序
include <windows.h> include <conio.h> void main(){ long int t;int flag =0;t = 86400;printf("press S start, press E stop\\n");while(1){ if (kbhit() == 'S' || kbhit() == 's') flag =1;if (kbhit() == 'E' || kbhit() == 'e') flag =0;Sleep(1000);i...

单片机时钟程序 24小时制
C语言的:include <reg51.h> include<stdio.h> unsigned char ledbuf[8];code unsigned char ledmap[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99,0x92, 0x82, 0xf8, 0x80, 0x90}; \/\/8段显示 void delay(unsigned char cnt){ unsigned char i;while(cnt--!=0)for(i=100;i!=0;i-...

相似回答