raynstard #7038(2008/08/07 05:51 GMT) [ C ] Rating0/0=0.00
Cだとmktime(3C)を使うと便利です。 まぁ、ほんとにmktime()が本領発揮するのは日時へ変換したときなのですけど^^;; // gcc -Wall -std=c99 doukaku197.c -o doukaku197
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <stdio.h> #include <time.h> static const char *weekdayname[] = {"Sun","Mon","Tue","Wed","Thi","Fri","Sat"}; int main(int argc, char *argv[]) { static const int YEAR_END = (2013 - 1900) + 1; struct tm t = {0}; time_t now = 0; int count = 0; now = time(NULL); localtime_r(&now, &t); t.tm_mday = 13; // 13日固定 /* 2014年までの13日の金曜日を検索する */ count = 0; while( t.tm_year < YEAR_END ) { // 13日の金曜日を探す if( t.tm_wday == 5 ) { // 13日の金曜日なら表示してカウントアップ printf("%d/%02d/%02d (%s)\n" , t.tm_year+1900, t.tm_mon+1, t.tm_mday , weekdayname[ t.tm_wday ]); count ++; } t.tm_mon ++; mktime( &t ); // 日時の再計算(正規化) } printf("COUNT:[%d]\n", count); return 0; } /* EOF */
Rating0/0=0.00-0+
[ reply ]
raynstard
#7038()
[
C
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]