当前位置: 技术问答>linux和unix
求救!!!三秒后输出一次系统时间问题、、、先谢谢了!!!
来源: 互联网 发布时间:2016-11-17
本文导语: #include #include #include int main() { int i=0; char s[]="Thu Jan 01 08:00:03 1970",a[50]={-1},*p;//想要它隔三秒输出一次系统时间Thu Jan 01 08:00:03 1970 time_t timep,timep1,timep2; time(&timep); time(&timep1); timep2=timep1-timep; ...
#include
#include
#include
int main()
{
int i=0;
char s[]="Thu Jan 01 08:00:03 1970",a[50]={-1},*p;//想要它隔三秒输出一次系统时间Thu Jan 01 08:00:03 1970
time_t timep,timep1,timep2;
time(&timep);
time(&timep1);
timep2=timep1-timep;
p=ctime(&timep2);
for(;*p!='';i++)
{
a[i]=*p;
p++;
}
printf("time is:%sn",a);
while(strcmp(a,s)!=0)
{
time(&timep1);
timep2=timep1-timep;
p=ctime(&timep2);
for(i=0;*p!='';i++)
{
a[i]=*p;
p++;
}
}
printf("time2 is:%sn",ctime(&timep1));
return 0;
}
为什么strcmp(a,s)!=0老是判断有问题,总是死循环、、、求教高手
#include
#include
int main()
{
int i=0;
char s[]="Thu Jan 01 08:00:03 1970",a[50]={-1},*p;//想要它隔三秒输出一次系统时间Thu Jan 01 08:00:03 1970
time_t timep,timep1,timep2;
time(&timep);
time(&timep1);
timep2=timep1-timep;
p=ctime(&timep2);
for(;*p!='';i++)
{
a[i]=*p;
p++;
}
printf("time is:%sn",a);
while(strcmp(a,s)!=0)
{
time(&timep1);
timep2=timep1-timep;
p=ctime(&timep2);
for(i=0;*p!='';i++)
{
a[i]=*p;
p++;
}
}
printf("time2 is:%sn",ctime(&timep1));
return 0;
}
为什么strcmp(a,s)!=0老是判断有问题,总是死循环、、、求教高手
|
The ctime subroutine converts a time value pointed to by the Clock parameter, which represents the time in seconds since 00:00:00 Coordinated Universal Time (UTC), January 1, 1970, into a 26-character string in the following form:
Sun Sept 16 01:03:52 1973n
Sun Sept 16 01:03:52 1973n