gmtime in C - Unix

This is a discussion on gmtime in C - Unix ; Hello, I am having some problems with gmtime in my C program. When I was first testing it, I had the following calls in my main: time_t now; struct tm *ts; char time_buf[80]; time(&now); ts = gmtime(&now); strftime(time_buf, sizeof(time_buf), "%a, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: gmtime in C

  1. gmtime in C

    Hello,

    I am having some problems with gmtime in my C program.


    When I was first testing it, I had the following calls in my main:

    time_t now;
    struct tm *ts;
    char time_buf[80];

    time(&now);
    ts = gmtime(&now);
    strftime(time_buf, sizeof(time_buf),
    "%a, %d %b %Y %H:%M:%S %Z", ts);

    This worked fine.

    However, I wanted to move it into a function call, and when I did
    that, it would stall at ts = gmtime(&now);

    However, if I keep the original (just a simple copy and past here) in
    the main() function, my calls in the function I made work just fine.
    Both calls have their own references to local variables that is not
    the problem (I even humored myself and changed the variable names in
    my function, and it still works iff I keep a pointless call in my
    main).

    What would be causing this?

  2. Re: gmtime in C

    Allan wrote:
    > Hello,
    >
    > I am having some problems with gmtime in my C program.
    >
    >
    > When I was first testing it, I had the following calls in my main:
    >
    > time_t now;
    > struct tm *ts;
    > char time_buf[80];
    >
    > time(&now);
    > ts = gmtime(&now);
    > strftime(time_buf, sizeof(time_buf),
    > "%a, %d %b %Y %H:%M:%S %Z", ts);
    >
    > This worked fine.
    >
    > However, I wanted to move it into a function call, and when I did
    > that, it would stall at ts = gmtime(&now);
    >
    > However, if I keep the original (just a simple copy and past here) in
    > the main() function, my calls in the function I made work just fine.
    > Both calls have their own references to local variables that is not
    > the problem (I even humored myself and changed the variable names in
    > my function, and it still works iff I keep a pointless call in my
    > main).
    >
    > What would be causing this?


    Maybe if you'd exhibit the code that *doesn't* work
    instead of the code that works, someone could do more than
    just guess. If your son is sick, do you take your daughter
    to the doctor?

    You might also want to expand on just what you mean
    by "it would stall." If you got a diagnostic from the
    compiler, what was the message? If the program aborted,
    what messages said so and how did you discover that the
    line you mentioned was the culprit? If the program compiles
    and runs and then just sits there, how did you pin the
    blame on that particular line?

    --
    Eric.Sosman@sun.com

  3. Re: gmtime in C

    >I am having some problems with gmtime in my C program.
    >
    >
    >When I was first testing it, I had the following calls in my main:
    >
    >time_t now;
    >struct tm *ts;
    >char time_buf[80];
    >
    >time(&now);
    >ts = gmtime(&now);
    >strftime(time_buf, sizeof(time_buf),
    > "%a, %d %b %Y %H:%M:%S %Z", ts);
    >
    >This worked fine.
    >
    >However, I wanted to move it into a function call, and when I did
    >that, it would stall at ts = gmtime(&now);


    Did you change the type of now? (say, to a time_t * from a time_t
    ?). Is it passed from main() to the function? How did you initialize
    now?

    >However, if I keep the original (just a simple copy and past here) in
    >the main() function, my calls in the function I made work just fine.
    >Both calls have their own references to local variables that is not
    >the problem (I even humored myself and changed the variable names in
    >my function, and it still works iff I keep a pointless call in my
    >main).
    >
    >What would be causing this?


    Show us the malfunctioning code. Otherwise, the bad code is always
    in line 42.



+ Reply to Thread