这道题就是表示时间,然后我的问题是为什么要有void ticktok(Time *p) 这个代码?因为我发现即使不使用这一行代码,显示出来也是对的啊,所以这个函数到底有身边么用?求解答,谢谢
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
typedef struct Time
{
int hour;
int minute;
int second;
}Time;
void ticktok(Time *p)
{
p ->second++;
if(p->second >= 60)
{
p->second = 0;
p->minute++;
{
if(p->minute >= 60)
{
p->minute = 0;
p->hour++;
if(p->hour >=24)
{
p->hour %= 24 ;
}
}
}
}
}
int main()
{
while(!kbhit())
{
int seconds = time(NULL);
Time now;
now.hour = (seconds/3600 +8 )%24;
now.minute = seconds/60%60;
now.second = seconds%60;
ticktok(&now);
printf("%d:%d:%d",now.hour,now.minute,now.second);
Sleep(1000);
system("cls");
}
}