帮忙看看这个程序,重分请!!

tiger_wkh52741 2002-01-17 12:21:32
#include<stdio.h>
#include<dos.h>
#include<conio.h>
struct time
{
unsigned char ti_min; //分钟
unsigned char ti_hour; //小时
unsigned char ti_hund; //hundredths of seconds
unsigned char ti_sec; //seconds
};
//--------------------------------------------------------------------
int main(void)
{
int hour=0,minute=0,second=0; // 定义变量
struct time T; //定义对象 T
clrscr(); //清屏
textcolor(12);
gettime(&T);
gotoxy(10,5);
cprintf("the current time is:%2d;%02d;%02d/n",
T.ti_hour,T.ti_min,T.ti_sec); //输出当前时间
textcolor(11);
gotoxy(10,7);
cprintf("Input the alarm time please!"); //要求用户输入定时时间
textcolor(YELLOW); //变换字体颜色
gotoxy(10,9);
cprintf("The hour(0-23):");
scanf("%d",&hour); //输入小时值
gotoxy(10,11);
cprintf("the minute(0-59):");
scanf("%d",&minute); //输入分钟值
gotoxy(10,13);
cprintf("The second(0-59):");
scanf("%d",&second); //输入秒钟值
while((hour*3600+minute*60+second-(T.ti_hour*3600
+T.ti_min*60+T.ti_sec))>0) //检查时间是否相等,不等则继续等
{
gettime(&T);
}
while(!kbhit()) //时间到闹铃响
sound(440);
nosound(); //直到有按键,才停止响声!
getch();
gotoxy(10,15);
textcolor(WHITE);
cprintf("Press any key to exit....."); //按任意键退出
getch();
return 0;
}


...全文
96 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiger_wkh52741 2002-01-17
  • 打赏
  • 举报
回复
哦,我的程序就是不执行啊,
我是啊,error总是说我的textcolor()没有定义类型,还有cprintf,nosound,sound
还有multiple declaration for'time'
undefined symbol "white"
undefined symbol"yellow"
summer_xzw 2002-01-17
  • 打赏
  • 举报
回复
你的程序怎么啦?
eion 2002-01-17
  • 打赏
  • 举报
回复
如果你用的是VC,看看着一段代码#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset();

/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );

/* Get UNIX-style time and display as number and string. */
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );

/* Display UTC. */
gmt = gmtime( <ime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

/* Convert to time structure and adjust for PM if necessary. */
today = localtime( <ime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;

/* Note how pointer addition is used to skip the first 11
* characters and printf is used to trim off terminating
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );

/* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n",
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" );

/* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

/* Use time structure to build a customized time string. */
today = localtime( <ime );

/* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}

MadLee 2002-01-17
  • 打赏
  • 举报
回复
这些都是tc自定义的函数,你用的是什么编译器?
kiss_me 2002-01-17
  • 打赏
  • 举报
回复
构思不错把你的电脑当闹钟。
divaly 2002-01-17
  • 打赏
  • 举报
回复
喂!time可是C自已的,我用time做变量名不就重定义啦!在dos.h里又提供了TIME这个结构啦!
你把time改成别的名就可以啦
juqiang 2002-01-17
  • 打赏
  • 举报
回复
agree to divaly
divaly 2002-01-17
  • 打赏
  • 举报
回复
回pajun,你说程序中哪个函数需要用到graphics.h,textcolor()是在conio.h定义的,根本就不用graphics.h
juqiang 2002-01-17
  • 打赏
  • 举报
回复
都是tc2.0里面的代码啊!只要包含conio.h就可以了。呵呵,这种代码现在没什么用处了。
pajun 2002-01-17
  • 打赏
  • 举报
回复
这是一段早期BC编译器的程序,不知道你是从哪儿发现的。首先,你少了个头文件<graphics.h>,里面有textcolor()等函数定义。而kbhit()是在<conio.h>中的。
至于time结构,应该在<dos.h>里已经有了吧,如果没猜错的话,这程序是BC3.x的。TC2.0也可以通过。
真难为你找到如此古老的东西。
panjet 2002-01-17
  • 打赏
  • 举报
回复
multiple declaration for'time'
time这个结构在 <dos.h>中已经定义了,你不需要自己再重新定义,把 struct time 注释掉

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧