Talk:Last Friday of each month

From Rosetta Code
Revision as of 01:05, 9 November 2011 by rosettacode>Kernigh (→‎C version: OpenBSD)

task name

of year? not of month?--eMBee 13:43, 7 November 2011 (UTC)

It looks like it's all of the last fridays of the months of a given year? --Rdm 14:52, 7 November 2011 (UTC)
yes, exactly, which is why i find the current title confusing. something like Last Friday of every month would be more to the point. otherwise, i thought the original title was sufficient. something about fridays. it is clear enough that this is about the calendar. is more details really needed?--eMBee 14:59, 7 November 2011 (UTC)

C version

Building the C version under cygwin (gcc 3.4.4), I get:

<lang bash>$ make last_fridays cc last_fridays.c -o last_fridays

$ ./last_fridays 2011 2011-01-27 2011-02-24 2011-03-31 2011-04-28 2011-05-26 2011-06-30 2011-07-28 2011-08-25 2011-09-29 2011-10-27 2011-11-24 2011-12-29

$ ./last_fridays 2012 2012-01-27 2012-02-24 2012-03-30 2012-04-27 2012-05-25 2012-06-29 2012-07-27 2012-08-31 2012-09-28 2012-10-26 2012-11-30 2012-12-28

$ cc --version cc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</lang>

The C entry currently shows different results for 2011, but I cannot reproduce them. --Rdm 23:25, 8 November 2011 (UTC)

I'll assume it's a cygwin bug for now. For the record, can you change two lines to
<lang>sprintf(buf, "%d-01-01 09:01:01", y);

strptime(buf, "%Y-%m-%d %H:%M:%S", &tm);</lang> and see how it does? --unsigned

I have a similar problem with OpenBSD 4.9. The output changes from run to run, and might show the last Mondays, Thursdays, Fridays or Saturdays. After the call to strptime(), tm.tm_wday contains junk values like 50237728 or 239567136. (Legal values are 0 to 6.) Change to "%d-01-01 09:01:01" and "%Y-%m-%d %H:%M:%S" is no help. Checking my manuals, mktime(3) describes the fields of struct tm, but strptime(3) is vague; I assume that strptime() never fills tm_wday unless the string contains the weekday. --Kernigh 01:05, 9 November 2011 (UTC)