Folks,
There are probably better ways than this but I hope this will spark some ideas.
If you want to test a users date input for validity, try using this to define your years!!
Struct Year
{
struct month
{
int no_of_days;
char *name; //optional field if you want month names
} months[12];
} leapyear, nonleapyear; //define year data in memory;
void main()
{
int i;
for(i = 0;i<12;i++)
{
switch(i+1)
{
case 1: nonleapyear.months.no_of_days = 31;
leapyear.months.no_of_days = 31;
break;
case 2: nonleapyear.months.no_of_days = 28;
leapyear.months.no_of_days = 29;
break;
.....
}
}
if you now get a user entry then you can compare string sections to the year variables month data, e.g. if month is greater than 12 then reject entry or (to put something in code) if day value is invalid, reject entry.
if((<compare value> > nonleapyear.months[month_id].no_of_days) ¦¦ (<compare value> < 1)
{
<error routine>
}
else
{
<accepted routine>
}
If anyone has any other ideas on this then please put them on this thread because dates are pretty complicated and I don't think I know enough to get the best out of them.
"Remember.. it's all gibberish until someone puts it in terms YOU understand..."
DanJC
There are probably better ways than this but I hope this will spark some ideas.
If you want to test a users date input for validity, try using this to define your years!!
Struct Year
{
struct month
{
int no_of_days;
char *name; //optional field if you want month names
} months[12];
} leapyear, nonleapyear; //define year data in memory;
void main()
{
int i;
for(i = 0;i<12;i++)
{
switch(i+1)
{
case 1: nonleapyear.months.no_of_days = 31;
leapyear.months.no_of_days = 31;
break;
case 2: nonleapyear.months.no_of_days = 28;
leapyear.months.no_of_days = 29;
break;
.....
}
}
if you now get a user entry then you can compare string sections to the year variables month data, e.g. if month is greater than 12 then reject entry or (to put something in code) if day value is invalid, reject entry.
if((<compare value> > nonleapyear.months[month_id].no_of_days) ¦¦ (<compare value> < 1)
{
<error routine>
}
else
{
<accepted routine>
}
If anyone has any other ideas on this then please put them on this thread because dates are pretty complicated and I don't think I know enough to get the best out of them.
"Remember.. it's all gibberish until someone puts it in terms YOU understand..."
DanJC