规范日期的输入
#include <stdio.h>
#include<conio.h>
void guifanrq(char time[])
{
int zs = 0;
char gf;
while(1)
{
gf = getch();
if(gf == '\b')
{
if(zs > 0)
{
printf("\b \b");
zs--;
}
if(zs == 4 || zs == 7)
{
printf("\b \b");
zs--;
}
}
if(gf >= '0' && gf <= '9')
{
if(zs >= 10)
continue;
//月规范
if(zs == 5)
if(gf > '1')
{
time[zs] = '1';
printf("1");
zs++;
continue;
}
if(zs == 6)
{
if(time[5] == '0')
if(gf == '0')
{
time[zs] = '1';
printf("1");
zs++;
}
else
{
time[zs] = gf;
printf("%c",gf);
zs++;
}
else
if(gf > '2')
{
time[zs] = '2';
printf("2");
zs++;
}
else
{
time[zs] = gf;
printf("%c",gf);
zs++;
}
printf("/");
time[zs] = '/';
zs++;
continue;
}
//日规范
if(zs == 8)
if(time[5] == '0' && time[6] == '2')
{
if(gf > '2')
{
time[zs] = '2';
printf("2");
zs++;
continue;
}
}
else
if(gf > '3')
{
time[zs] = '3';
printf("3");
zs++;
continue;
}
if(zs == 9)
{
if(time[5] == '0' && time[6] == '2' && time[8] == '2')
{
if(((time[2] -'0') *10 + (time[3]- '0')) %4 != 0 || (time[2] == '0' && time[3] == '0'))
if(gf > '8')
{
time[zs] = '8';
printf("8");
zs++;
continue;
}
}
else
if(time[8] == '0')
if(gf == '0')
{
time[zs] = '1';
printf("1");
zs++;
continue;
}
if(time[8] == '3')
if(time[5] == '0')
if(time[6] == '1' || time[6] == '3' || time[6] == '5' || time[6] == '7' || time[6] == '8')
{
if(gf > '1')
{
time[zs] = '1';
printf("1");
zs++;
continue;
}
}
else
{
if(gf > '0')
{
time[zs] = '0';
printf("0");
zs++;
continue;
}
}
else
if(time[6] == '1')
{
if(gf > '0')
{
time[zs] = '0';
printf("0");
zs++;
continue;
}
}
else
{
if(gf > '1')
{
time[zs] = '1';
printf("1");
zs++;
continue;
}
}
}
time[zs] = gf;
printf("%c",gf);
zs++;
if(zs == 4 || zs == 7)
{
printf("/");
time[zs] = '/';
zs++;
}
}
else
if(gf == 13 && zs >= 10)
break;
}
time[zs] = 0;
}
main()
{
char time[11];
while(1)
{
guifanrq(time);
printf("\n|| %s ||\n",time);
}
}