/* Input year, month, day, hour, minute, second, and output year, month, day, hour, minute, second. The output is still in the original memory space */
Void nextminute (int * nyear, int * nmonth, int * ndate, int * nhour, int * nminute, int * nsecond)
{
Int ndays;
(* Nsecond) ++;/* second plus 1 */
If (* nsecond> = 60)/* If the second is 60, special processing is performed. The following time, day, month, and so on are similar */
{
* Nsecond = 0;
(* Nminute) ++;
If (* nminute> = 60)
{
* Nminute = 0;
(* Nhour) ++;
If (* nhour> = 24)
{
* Nhour = 0;
(* Ndate) ++;
Switch (* nmonth)
{
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
Ndays = 31;
Break;
Case 2:/* determine a leap year */
If (* nyear % 400 = 0 | * nyear % 100! = 0 & * nyear % 4 = 0)
{
Ndays = 29;
}
Else
{
Ndays = 28;
}
Break;
Default:
Ndays = 30;
Break;
}
If (* ndate> = ndays)
{
* Ndate = 1;
(* Nmonth) ++;
If (* nmonth> 12)
{
* Nmonth = 1;
(* Nyear) ++;
}
}
}
}
}
}
/* The sample code can be run */
Void main ()
{
Int nyear = 2004, nmonth = 12, ndate = 31, nhour = 59, nminute = 59, nsecond = 59;
Nextminute (& nyear, & nmonth, & ndate, & nhour, & nminute, & nsecond );
Printf ("the result: % d-% d: % d", nyear, nmonth, ndate, nhour, nminute, nsecond );
Getch ();
}