大家来帮忙看看这段代码,有关问题出在哪了
大家来帮忙看看这段代码,问题出在哪了?
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <time.h>
typedef struct _time {
int seconds;
int minutes;
int hours;
}TIME,*LPTime;
void InitTime(LPTime time);
void UpdateTime(LPTime time);
void ShowTime(LPTime time);
void delay(int i);
int main()
{
LPTime systemtime;
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 {
int seconds;
int minutes;
int hours;
}TIME,*LPTime;
LPTime& InitTime(LPTime time);
void UpdateTime(LPTime time);
void ShowTime(LPTime time);
void delay(int i);
int main()
{
LPTime systemtime;
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);
}
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <time.h>
typedef struct _time {
int seconds;
int minutes;
int hours;
}TIME,*LPTime;
void InitTime(LPTime time);
void UpdateTime(LPTime time);
void ShowTime(LPTime time);
void delay(int i);
int main()
{
LPTime systemtime;
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 {
int seconds;
int minutes;
int hours;
}TIME,*LPTime;
LPTime& InitTime(LPTime time);
void UpdateTime(LPTime time);
void ShowTime(LPTime time);
void delay(int i);
int main()
{
LPTime systemtime;
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);
}