Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #157548

Re: I need help understand some c code

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: I need help understand some c code
Date 2020-12-20 20:43 -0800
Organization None to speak of
Message-ID <87h7ofbwh5.fsf@nosuchdomain.example.com> (permalink)
References <rrp1gb$kle$1@dont-email.me> <87lfdrbymy.fsf@nosuchdomain.example.com> <rrp6o0$ip9$1@dont-email.me>

Show all headers | View raw


T <T@invalid.invalid> writes:
> On 12/20/20 7:56 PM, Keith Thompson wrote:
>> t = time(NULL);
>
> I found this on stack overflow:
>
> int main (void)
> {
>     //print time in seconds from 1 Jan 1970 using c
>     float n = time(NULL);
>     printf("%.2f\n" , n);
> }

This converts time_t to float.  There's no good reason to do that.

> "seconds from 1 Jan 1970" ????

Yes, that's what the time() function returns in most implementions,
though it's implementation-defined.

> I am just after something like 21:04:55
> 
> Is there a better call for this?

time() gives you a value that you can pass to other functions to
interpret its meaning.  <time.h> is documented in section 7.27 of N1570:
    http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf
For more user-friendly documentation, see
    https://en.cppreference.com/w/c/chrono
or any decent C reference or tutorial.

gmtime() or localtime() converts a time_t to a struct tm, which
represents a time broken down into its components.

If you're going to be working with C as much as your questions suggest,
you would do well to learn the basics of the language.  You can't do so
by posting questions about one feature at a time.  (I mentioned this to
you a couple of years ago.)

[I just noticed that I had flagged you in my newsreader early last
year, for repeatedly posting off-topic replies.  Please refrain
from doing so again.]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I need help understand some c code T <T@invalid.invalid> - 2020-12-20 18:32 -0800
  Re: I need help understand some c code Siri Cruise <chine.bleu@yahoo.com> - 2020-12-20 19:03 -0800
  Re: I need help understand some c code Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-20 19:56 -0800
    Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-20 20:02 -0800
      Re: I need help understand some c code Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-20 20:43 -0800
        Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-20 21:06 -0800
          Re: I need help understand some c code Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-20 21:56 -0800
  Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-20 20:33 -0800
    Re: I need help understand some c code Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-20 20:51 -0800
      Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-20 21:11 -0800
        Re: I need help understand some c code Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-20 22:10 -0800
          Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-20 22:15 -0800
      Re: I need help understand some c code Bart <bc@freeuk.com> - 2020-12-21 13:11 +0000
        Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-21 13:47 -0800
          Re: I need help understand some c code scott@slp53.sl.home (Scott Lurndal) - 2020-12-23 17:18 +0000
            Re: I need help understand some c code Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-23 12:05 -0800
        Re: I need help understand some c code T <T@invalid.invalid> - 2020-12-21 14:25 -0800
  Re: I need help understand some c code Bonita Montero <Bonita.Montero@gmail.com> - 2020-12-21 05:45 +0100
  Re: I need help understand some c code Bart <bc@freeuk.com> - 2020-12-21 12:16 +0000
  Re: I need help understand some c code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-12-21 20:03 +0000

csiph-web