求助 C++程序
#include "stdafx.h"
#include <time.h>
#include <iostream>
#include <Windows.h>
using std::cout;
using std::endl;
void S_timer()
{ int year1,mon1,day1,hour1,minu1,sec1;
year1=mon1=day1=hour1=minu1=sec1=0;
scanf("%d%d%d%d%d%d",&year1,&mon1,&day1,&hour1,&minu1,&sec1);
time_t times;
tm *tf = new tm;
while(true)
{
times = time(NULL);
Sleep(10);
localtime_s(tf,×);
if(tf->tm_year + 1900 == year1 && tf->tm_mon +1 == mon1 && tf->tm_mday == day1 && tf->tm_hour == hour1 && tf->tm_min == minu1 && tf->tm_sec == sec1)
{
cout <<"STAR" << endl;
break;
}
}
}
void E_timer()
{ int year2,mon2,day2,hour2,minu2,sec2;
year2=mon2=day2=hour2=minu2=sec2=0;
scanf("%d%d%d%d%d%d",&year2,&mon2,&day2,&hour2,&minu2,&sec2);
time_t times;
tm *tf = new tm;
while(true)
{
times = time(NULL);
Sleep(10);
localtime_s(tf,×);
if(tf->tm_year + 1900 == year2 && tf->tm_mon +1 == mon2 && tf->tm_mday == day2 && tf->tm_hour == hour2 && tf->tm_min == minu2 && tf->tm_sec == sec2)
{
cout <<"The END" << endl;
break;
}
}
}
int main()
{
printf("输入开始和结束时间例如2012 8 28 11 2 30\nS_Time和E_Time:");
S_timer();
E_timer();
return 0;
}
为什么我把scanf 函数放到main函数里 程序无法正常执行,但是放到被调用函数又不能一次输入完两个时间(需要执行完S_才出现输入符号)。 请大神指点~
[解决办法]
你可以把那些年月日的整数设成全局变量,再到main函数里面输入应该是没有问题的。