#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 */
