我必须编写一个sleep(60)
在无限循环中调用的程序。通过循环每五次我必须获取当前时间并打印 tm_sec 字段。
这是我写的:
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
int main()
{
struct tm t1;
int i=0;
for(;;)
{
sleep(60);
if(i%5==0)
{
gettimeofday(&t1,NULL);
printf("%d\n",t1.tm_sec);
}
i++;
}
}
我收到一条错误消息aggregate tm t1 has incomplete type and cannot be defined.
我不知道我做错了什么。