C程序闹钟程序或者定时提醒
答案:1 悬赏:80 手机版
解决时间 2021-05-10 11:32
- 提问者网友:眉目添风霜
- 2021-05-10 04:50
C程序闹钟程序或者定时提醒
最佳答案
- 五星知识达人网友:深街酒徒
- 2021-05-10 05:53
给,已经编译运行确认了:
#include<conio.h>
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
int GetHour(char *s)
{
char *p, *q;
p = (char *)malloc(10);
strcpy(p, s);
q = p;
while(*q != ':')
{
q++;
}
*q = '\0';
return atoi(p);
}
int GetMinute(char *s)
{
char *p;
p = (char *)malloc(10);
strcpy(p, s);
while(*p != ':')
{
p++;
}
p++;
return atoi(p);
}
main()
{
char s[10];
int hour,minute;
time_t t;
struct tm *timeinfo;
printf("please input the time like [18:30]:\n");
gets(s);
hour = GetHour(s);
minute = GetMinute(s);
while(1)
{
time(&t);
timeinfo = localtime(&t);
if(timeinfo->tm_hour < hour)continue;
else if(timeinfo->tm_min < minute)continue;
else
{
printf("Time is up!Wake up!\n\007");
printf("\a\a\a\a");
exit(0);
}
}
}
#include<conio.h>
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
int GetHour(char *s)
{
char *p, *q;
p = (char *)malloc(10);
strcpy(p, s);
q = p;
while(*q != ':')
{
q++;
}
*q = '\0';
return atoi(p);
}
int GetMinute(char *s)
{
char *p;
p = (char *)malloc(10);
strcpy(p, s);
while(*p != ':')
{
p++;
}
p++;
return atoi(p);
}
main()
{
char s[10];
int hour,minute;
time_t t;
struct tm *timeinfo;
printf("please input the time like [18:30]:\n");
gets(s);
hour = GetHour(s);
minute = GetMinute(s);
while(1)
{
time(&t);
timeinfo = localtime(&t);
if(timeinfo->tm_hour < hour)continue;
else if(timeinfo->tm_min < minute)continue;
else
{
printf("Time is up!Wake up!\n\007");
printf("\a\a\a\a");
exit(0);
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯