int dayInMonthFromDayInYear(int dayInYear, bool leapYear) { const int d = dayInYear; int step; int next = 30; if (d <= next) return d + 1; const int daysInFeb = (leapYear ? 29 : 28); if (checkMonth(d, step, next, daysInFeb)) return d - step; if (checkMonth(d, step, next, 31)) return d - step; if (checkMonth(d, step, next, 30)) return d - step; if (checkMonth(d, step, next, 31)) return d - step; if (checkMonth(d, step, next, 30)) return d - step; if (checkMonth(d, step, next, 31)) return d - step; if (checkMonth(d, step, next, 31)) return d - step; if (checkMonth(d, step, next, 30)) return d - step; if (checkMonth(d, step, next, 31)) return d - step; if (checkMonth(d, step, next, 30)) return d - step; step = next; return d - step; }
int dayInMonthFromDayInYear(const int dayInYear, const bool leapYear) { int step; int next = 30; if (dayInYear <= next) return dayInYear + 1; const int daysInFeb = (leapYear ? 29 : 28); if (checkMonth(dayInYear, step, next, daysInFeb)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 31)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 30)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 31)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 30)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 31)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 31)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 30)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 31)) return dayInYear - step; if (checkMonth(dayInYear, step, next, 30)) return dayInYear - step; step = next; return dayInYear - step; }
int checkDate(int year, int month, int day) { // 1 ~ 12월 입력했는지 확인 if (!checkMonth(month)) { printf("1 ~ 12월로 입력해주세요.\n"); return 0; } else if (!checkDay(year, month, day)) { printf("%d년 %d월 %d일은 존재하지 않습니다.\n", year, month, day); return 0; } return 1; }
/* The actual read function. */ void readin() { char* fname = ( char* )malloc( sizeof( char ) * 26 ) ; // The extra length for the null terminator. readName( fname, 0, 26 ) ; char* lname = ( char* )malloc( sizeof( char ) * 31 ) ; readName( lname, 1, 31 ) ; char* cardnum = ( char* )malloc( sizeof( char ) * 17 ) ; readNums( cardnum, 0, 17 ) ; char* month = ( char* )malloc( sizeof( char ) * 3 ) ; readNums( month, 1, 3 ) ; while( !checkMonth( month ) ) { printf( "The entered month is not valid. Please try again.\n" ) ; readNums( month, 1, 3 ) ; } char* year = ( char* )malloc( sizeof( char ) * 5 ) ; readNums( year, 2, 5 ) ; while( !checkYear( year ) ) { printf( "The entered year is not valid. Please try again.\n" ) ; readNums( year, 2, 5 ) ; } char* cvv = ( char* )malloc( sizeof( char ) * 4 ) ; readNums( cvv, 3, 4 ) ; if( strlen( cvv ) != 3 ) // String already checked for numbers. Check if all three are there. { printf( "Not enough digits for 3 digit CVV security code. Please try again. \n" ) ; readNums( cvv, 3, 4 ) ; } char* zip = ( char* )malloc( sizeof( char ) * 6 ) ; readNums( zip, 4, 6 ) ; if( strlen( zip ) != 5 ) { printf( "Not enough numbers for 5 digit zipcode. Please try again.\n" ) ; readNums( zip, 4, 6 ) ; } char* amount = ( char* )malloc( sizeof( char ) * 10 ) ; readAmount( amount, 10 ) ; char* email = ( char* )malloc( sizeof( char ) * 25 ) ; readEmail( email, 31 ) ; display( fname, lname, cardnum, month, year, cvv, zip, amount, email ) ; // Free up all the memory pointers used here. free( fname ) ; free( lname ) ; free( cardnum ) ; free( month ) ; free( year ) ; free( cvv ) ; free( zip ) ; free( amount ) ; free( email ) ; }