Need HELP with strptime....any answers/clues????? 
Author Message
 Need HELP with strptime....any answers/clues?????


Quote:
>Hi:

>I have been working with some of the time functions (on a Sun
>SPARCstation IPX).  After I make a call to strptime (to fill
>in the tm structure) I display the structure (with dbxtool) and
>find that the structure is filled in incorrectly.  What am I
>doing wrong?

>Please, e-mail me with the answer. Below is some example code.

>Thanks for your time,
>Jon

>        ---------- Example Call to AsciiToTime ----------
>                            :
>                            :
>                            :
>    timeStatus = AsciiToTime("1990,123/065301.123");
>                            :
>                            :
>                            :

>        ---------- Module and Call in Question ----------
>#include    <time.h>

>AsciiToTime(timeString)
>char        *timeString;
>{
>    struct  tm      *my_tm;

>    /* Convert time string into the time structure (my_tm) */
>    (void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);

strptime does not understand that the hour, minute, and second are only
certain lengths.  You need to have some other token to split the fields
like a colon, or space.

Quote:

>/* ---> After the above call to strptime the tm structure is not filled
>    in correctly. What am I doing wrong ??????
>*/

>    return(0);
>}

--

TAC System Administrator, US Army Corps of Engineers
Construction Engineering Research Labs, Champaign IL USA
/* Contract employee, and do you think some federal paper pusher */


Wed, 07 Jun 1995 03:47:52 GMT  
 Need HELP with strptime....any answers/clues?????
Hi:

I have been working with some of the time functions (on a Sun
SPARCstation IPX).  After I make a call to strptime (to fill
in the tm structure) I display the structure (with dbxtool) and
find that the structure is filled in incorrectly.  What am I
doing wrong?

Please, e-mail me with the answer. Below is some example code.

Thanks for your time,
Jon

        ---------- Example Call to AsciiToTime ----------
                                :
                                :
                                :
        timeStatus = AsciiToTime("1990,123/065301.123");
                                :
                                :
                                :

        ---------- Module and Call in Question ----------

#include        <time.h>

AsciiToTime(timeString)
char    *timeString;
{
        struct  tm      *my_tm;

        /* Convert time string into the time structure (my_tm) */
        (void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);

/* ---> After the above call to strptime the tm structure is not filled
        in correctly. What am I doing wrong ??????
*/

        return(0);

Quote:
}



Mon, 05 Jun 1995 06:58:57 GMT  
 Need HELP with strptime....any answers/clues?????

Quote:


>>Hi:

>>I have been working with some of the time functions (on a Sun
>>SPARCstation IPX).  After I make a call to strptime (to fill
>>in the tm structure) I display the structure (with dbxtool) and
>>find that the structure is filled in incorrectly.  What am I
>>doing wrong?
...

>>AsciiToTime(timeString)
>>char    *timeString;
>>{
>>        struct  tm      *my_tm;

>>        (void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);

my_tm needs to be initialized to point to a struct tm before
asking strptime to fill it in.




Sat, 10 Jun 1995 01:25:42 GMT  
 Need HELP with strptime....any answers/clues?????

|>
|> >>I have been working with some of the time functions (on a Sun
|> >>SPARCstation IPX).  After I make a call to strptime (to fill
|> >>in the tm structure) I display the structure (with dbxtool) and
|> >>find that the structure is filled in incorrectly.  What am I
|> >>doing wrong?
|> ...
|> >>  struct  tm      *my_tm;
|> >>
|> >>  (void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);
|>
|> my_tm needs to be initialized to point to a struct tm before
|> asking strptime to fill it in.
|>

I had problems with strptime on the Sun a few months ago and
came to the conclusion that it was broken. Are you saying that
the following should work?

#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>

main()
{
   static char *s = "19920901111500";
   struct tm *tm;
   time_t tloc;

   time(&tloc);
   tm = localtime(&tloc);
   strptime(s, "%Y%m%d%H%M%S", tm);
   tloc = timelocal(tm);

   printf("Converted %s to %s, tloc = %ld\n",
      s, ctime(&tloc), tloc);

Quote:
}

I have also tried:

int main()
{
   static char *s = "19920901111500";
   struct tm tm;
   time_t tloc;

   strptime(s, "%Y%m%d%H%M%S", &tm);
   tloc = timelocal(&tm);
   ...

No matter how I twist things it always fails.

-- Alan.
--------------------------------------------

BT, Software Engineering Centre, Glasgow, UK
--------------------------------------------



Sun, 11 Jun 1995 02:53:09 GMT  
 Need HELP with strptime....any answers/clues?????
Thank you to everyone who replied to my posting regarding the
broken-ness of strptime. I had something like:

   buf = "19921230033515"
   strptime(buf, "%Y%m%d%H%M%S", tm);

The problem is that strptime parses this string (buf) as one number
which is too large, rather than lots of two- and four-digit numbers.
What I needed were a few delimiters - like spaces. My excuse is that
this never occured to me because I was also using strftime and in
this case it is perfectly okay not to use spaces, i.e.

   strftime(buf, DATE_SZ, "%Y%m%d%H%M%S", tm);

I was simply looking for a converse operation. The manual page does
not specify how the format string should be parsed. My fault for not
thinking clearly. Okay so it's not a good excuse.

The following works:

   buf = "1992 12 30 03 35 15";
   strptime(buf, "%Y %m %d %H %M %S", tm);

Thanks,

-- Alan
--------------------------------------------

BT, Software Engineering Centre, Glasgow, UK
--------------------------------------------



Mon, 19 Jun 1995 00:30:58 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. I need source for strptime function

2. Need while loop clue(was Summing Function)

3. need a clue with text

4. Help with strptime(3V)

5. Help... V Simple Questions Need Answering

6. Help!!! need an answer to a project

7. Help me please... I need help ASAP... I need an answer by Wednesday

8. libc strptime not working

9. libc strptime not working

10. Porting UNIX to WIN32 - strptime() function

11. strptime

12. Question(newbie): strptime alternative

 

 
Powered by phpBB® Forum Software