Dom rewrote my simple clock
https://z88dk.org/forum/viewtopic.php?p=19905#p19905
and now i have a bit to big routine that actualy should work in a single line
it calculates the length of a month in days. just a simple calc.
it DOES give a compile warning about atol ??
Code: Select all
// gcc monthdays.c -o monthdays -lm 2> monthdays.log
// modulo MONTH of 28+1,30 or 31 days,data table or calc?
// |01 02 03 04 05 06 07 |08 09 10 11 12 |
// |jan feb+ly mch apr may jun jul |aug sep oct nov dec|
// odd=1-7 b4=0 |31, 28+leapyear, 31, 30, 31, 30, 31, |31, 30, 31, 30, 31|
// even=8-12 b4=1 |odd=30+1 feb=30-2+leapyear |even=30+1 |
// odd = (month % 2) * (month>7)
// monthlen = 30 +odd -2*(month=2) +leapyear*(month=
// this routine should be only a SINGLE line with 2 or max 4 variables, month, monthlen, leapyear, odd
#include <stdio.h>
int main (int argc, char *argv[])
{
int leapyear, odd, month, monthlen ;
month = atol(argv[1]) ;
leapyear = atol(argv[2]) ;
printf ("month %d\n",month);
odd = month % 2;
printf("odd %d\n");
if (month > 7) odd=!(month % 2) ;
printf("odd %d\n");
monthlen = 30 ;
monthlen = monthlen + odd ;
monthlen = monthlen - 2*( month == 2) ;
monthlen = monthlen + leapyear*( month == 2) ;
printf( "month %d = %d days in LP=%d being odd %d \n", month, monthlen, leapyear, odd);
return monthlen;
}