首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2012-02-22 
大家来帮忙看看这段代码,问题出在哪了?#includewindows.h#includestdio.h#includestdlib.h#include

大家来帮忙看看这段代码,问题出在哪了?
#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);
}

热点排行