TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: JAVIER KOHEN
from: GEORGE WHITE
date: 1998-02-21 08:26:00
subject: Atotm

Hi Javier,
JK>"Converts strings formated as asctime output to struct tm."
JK>I'd like commentaries on this one.
OK
JK>>>>>>>>>>> CSplit: Version 2.2 >>>>>>>>>>
JK>>>>>>>>>>> CSplit: Begin part 1/1 >>>>>>>>>>
JK>>>>>>>>>>> CSplit: Begin file ATOTM.C >>>>>>>>>>
JK>/*
JK>** atotm.c - Converts strings formated as asctime output to struct tm.
JK>**
JK>** Given to Public Domain by Javier Kohen.
JK>*/
JK>#include 
JK>#include 
JK>#include 
JK>#include "scaldate.h"
JK>#include "atotm.h"
JK>static const char months[12][4] = {
JK> "Jan", "Feb", "Mar", "Apr", "May", "Jun",
JK> "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
JK>};
JK>struct tm atotm(const char *str) {
JK>    int i;
JK>    char month[4];
JK>    struct tm timer;
As you are returning the struct, I think it really needs to be static.
JK>    /* Redundant width specifiers, maybe some scanf implementation
JK>       works better with fixed widths, or maybe not */
JK>    if (6 != sscanf(str, "%*3s %3s %2d %2d:%2d:%2d %4d\n",
JK>     month, &timer.tm_mday, &timer.tm_hour,
JK>     &timer.tm_min, &timer.tm_sec, &timer.tm_year)) {
JK>        /* Returns a zeroed struct when a parse error occurs */
JK>        const struct tm zero = { 0 };
JK>        return (zero);
JK>    }
JK>    timer.tm_year -= 1900;
JK>    /* Convert month string to index number */
JK>    for (i = 0; i < 12; i++) {
JK>        if (0 == strcmp(month, months[i])) {
JK>            timer.tm_mon = i;
JK>            break;
JK>        }
JK>    }
JK>    timer.tm_wday = dow(timer.tm_year, timer.tm_mon, timer.tm_mday);
As you have the day available as a string from the input, did you
consider converting it in a similar way to the month rather than useing
an independant calculation?
 the rest, any comments are stylistic...
George
 * SLMR 2.1a * All Trademarks acknowledged (just in case ).
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.