学C不久。VC6写了一个控制台的,修改时个人时间不能后台走。你可以试试在mytime下面加多一个case到change()修改时也显示gomytime()的内容。#include
#include
#include
#include
void systime();
void mytime();
void wel();
void gomytime();
void change();
int ye,mo,da,ho,mi,se;
void main( )
{
wel();
}
//界面
void wel()
{
int k;
printf( "电子时钟\n" );
printf( "\n" );
printf( "1新建我的时间,2为系统时间,3为修改时间,4去我的时间,5退出\n" );
printf( "\n" );
printf( "选择:" );
scanf( "%d", &k );
switch ( k )
{
case 1:
mytime();
break;
case 2:
systime();
break;
case 3:
change();
break;
case 4:
gomytime();
break;
case 5:
exit(0);
break;
}
}
//个人设定的时间并行走
void mytime(){
int k;
printf("输入年:");
scanf("%d",&ye);
printf("输入月:");
scanf("%d",&mo);
printf("输入日:");
scanf("%d",&da);
printf("输入时:");
scanf("%d",&ho);
printf("输入分:");
scanf("%d",&mi);
printf("输入秒:");
scanf("%d",&se);
while(1)
{
Sleep(1000);
system("cls");
se++;
if(se>=60)
{
se-=60;
mi++;
if(mi>=60)
{
mi-=60;
ho++;
if(ho>=24)
{
da++;
ho-=24;
if(da>=30)
{
mo++;
da-=30;
if(mo>=12)
{
ye++;
mo-=12;
}
}
}
}
}
printf("电子时钟\n");
printf("\n");
printf("个人设定的时间:");
printf("%d年%d月%d日%d时%d分%d秒", ye,mo,da,ho, mi, se);
printf("\n");
printf("\n");
printf("1为返回,2为继续\n");
printf("选择:");
if(kbhit())
{
scanf("%d",&k);
break;
}
}
switch(k){
case 1:
system("cls");
wel();
break;
case 2:
gomytime();
break;
}
}
//个人时间行走
void gomytime(){
int k;
while(1)
{
Sleep(1000);
system("cls");
se++;
if(se>=60)
{
se-=60;
mi++;
if(mi>=60)
{
mi-=60;
ho++;
if(ho>=24)
{
da++;
ho-=24;
if(da>=30)
{
mo++;
da-=30;
if(mo>=12)
{
ye++;
mo-=12;
}
}
}
}
}
printf("电子时钟\n");
printf("\n");
printf("个人设定的时间:");
printf("%d年%d月%d日%d时%d分%d秒", ye,mo,da,ho, mi, se);
printf("\n");
printf("\n");
printf("1为返回,2为继续\n");
printf("选择:");
if(kbhit())
{
scanf("%d",&k);
break;
}
}
switch(k){
case 1:
system("cls");
wel();
break;
case 2:
gomytime();
break;
}
}
//系统时间
void systime(){
int k;
int year, month, day,hour,min,sec;
time_t nowtime;
struct tm *timeinfo;
while(1)
{
Sleep(1000);
system("cls");
time( &nowtime );
timeinfo = localtime( &nowtime );
year = timeinfo->tm_year + 1900;
month = timeinfo->tm_mon + 1;
day = timeinfo->tm_mday;
hour = timeinfo->tm_hour;
min = timeinfo->tm_min;
sec = timeinfo->tm_sec;
printf("电子时钟\n");
printf("\n");
printf("系统时间:%d年 %d月 %d日", year, month, day);
printf("%d时 %d分 %d秒\n", hour, min, sec);
printf("\n");
printf("1为返回,2为继续\n");
printf("选择:");
if(kbhit())
{
scanf("%d",&k);
break;
}
}
switch(k){
case 1:
system("cls");
wel();
break;
case 2:
systime();
break;
}
}
//修改个人时间
void change()
{
int k;
system( "cls" );
printf( "电子时钟\n" );
printf( "\n" );
printf( "修改我的时间\n" );
printf( "1为修改年,2为修改月,3为修改日,4为修改时,5为修改分,6为修改秒,7我的时间,8返回" );
printf( "\n" );
printf( "选择:" );
scanf( "%d", &k );
switch ( k )
{
case 1:
printf( "修改年:" );
scanf( "%d", &ye );
change();
break;
case 2:
printf( "修改月:" );
scanf( "%d", &mo );
change();
break;
case 3:
printf( "修改日:" );
scanf( "%d", &da );
change();
break;
case 4:
printf( "修改时:" );
scanf( "%d", &ho );
change();
break;
case 5:
printf( "修改分:" );
scanf( "%d", &mi );
change();
break;
case 6:
printf( "修改秒:" );
scanf( "%d", &se );
change();
break;
case 7:
gomytime();
break;
case 8:
system( "cls" );
wel();
break;
}
}