读书人

大家来帮忙看看这段代码有关问题出在

发布时间: 2012-02-22 19:36:56 作者: rapoo

大家来帮忙看看这段代码,问题出在哪了?
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <time.h>

typedef struct _time{
intseconds;
intminutes;
inthours;
}TIME,*LPTime;

void InitTime(LPTime time);
void UpdateTime(LPTime time);
void ShowTime(LPTime time);
void delay(int i);

int main()
{
LPTimesystemtime;

InitTime(systemtime);

for(;;){
UpdateTime(systemtime);
ShowTime(systemtime);
Sleep(100);
}
return 0;
}

void InitTime(LPTime time)
{
time=(LPTime)malloc(sizeof(TIME));

if (!time)
{
printf( "Error!!!\n ");
exit(0);
}

time-> hours=0;
time-> minutes=0;
time-> seconds=0;


}
void UpdateTime(LPTime time)
{
time-> seconds++;
if(time-> seconds==60)
{
time-> seconds=0;
time-> minutes++;
}
if(time-> minutes==60)
{
time-> minutes=0;
time-> hours++;
}
if(time-> hours==24)
{
time-> hours=0;
}
}

void ShowTime(LPTime time)
{
printf( "%02d: ",time-> hours);
printf( "%02d: ",time-> minutes);
printf( "%02d\r ",time-> seconds);
}

[解决办法]
初步的改了一下,楼主看看:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <time.h>

typedef struct _time{
intseconds;
intminutes;
inthours;
}TIME,*LPTime;

LPTime& InitTime(LPTime time);
void UpdateTime(LPTime time);
void ShowTime(LPTime time);
void delay(int i);

int main()
{
LPTimesystemtime;

systemtime=InitTime(systemtime);

for(;;){
UpdateTime(systemtime);
ShowTime(systemtime);
Sleep(100);
}
return 0;
}

LPTime& InitTime(LPTime time)
{
time=(LPTime)malloc(sizeof(TIME));

if (!time)
{
printf( "Error!!!\n ");
exit(0);
}

time-> hours=0;
time-> minutes=0;
time-> seconds=0;
return time;

}
void UpdateTime(LPTime time)
{
time-> seconds++;
if(time-> seconds==60)
{
time-> seconds=0;
time-> minutes++;
}
if(time-> minutes==60)
{
time-> minutes=0;
time-> hours++;
}
if(time-> hours==24)
{
time-> hours=0;
}
}

void ShowTime(LPTime time)
{
printf( "%02d: ",time-> hours);
printf( "%02d: ",time-> minutes);
printf( "%02d\r ",time-> seconds);
}

读书人网 >C语言

热点推荐