Han said:
Hi there!
Here's how to display the values:
------------------------------------------------------------------------
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm *tp;
char tstr[256];
t = time(NULL);
t may be (time_t)(-1) if it can't return the time.
t may be NULL if localtime cannot convert to local time.
/* returns 0 if output won't fit in tstr - in which case,
don't assume anything about the contents of tstr. */
strftime(tstr, sizeof tstr,
"Day: %d\n"
"Hour: %H\n"
"Minute: %M\n"
"Second: %S\n", tp);
It's going to be interesting when tp-><something> is checked when tp is
NULL. Oh, no... Segmentation fault.
t = time(NULL);
tp = localtime(&t);
Again, a small problem with NULL.
The above are strictly conforming C programs.
However, you should add some safeguards.
Now for the %N case.
You're on Ubuntu Linux, presumably.
Can you say that for sure? If yes, what makes you think that (for sure)?
The date(1) command on your system
is from GNU coreutils. GNU date(1) has a %N extension for nanoseconds
that is implemented by, in order of preference:
nanotime()
Can't find it in the manpages.
clock_gettime(CLOCK_REALTIME, ...)
gettimeofday() with crappy resolution
Those three functions are on-topic here (see my topicality guidelines
below), so if you pick one, I'll teach you how to use it.
Hopefully, you know more about these than about the functions in
Good luck with your C programming
Yep... he'll need it.
Whether this newsgroup is strictly for ANSI/ISO C is a matter of opinion,
since this newsgroup has no charter and, in fact, has a founding message
that predates ANSI/ISO C. The spirit of the founding message was that this
newsgroup would be for discussions of C and anything tangential to C.
Nobody who has come along so far has any right to rewrite the founding
message and impose an ANSI/ISO C topicality restriction on this newsgroup,
whether by informal echo-chamber vote of a few dozen "regulars" or not.
"any right"? You can't handle "any right".
As long as your posts are about C or matters tangential to C, plenty of
people here will be happy to assist you. To get the most coverage for your
questions, however, you have the option of cross-posting to all relevant
newsgroups, including this one. That way, you have more experts available
to contribute answers.
Yes, but not everyone knows the relevant newsgroups so it's your duty to
point them out before giving bad advice with no one to call you out on it.
When deciding whom to listen to, take into account who helps you and who
doesn't. It's pretty hard to ignore someone who's giving you the help you
seek.
Yes, get into cars with strangers that give you candy.
<snip Han's self description>
kick you off to another newsgroup.
ref1 ^^^
They may say
something about the experts being able to correct one another's posts over
there, but that's a poor argument for at least two reasons: (1) As I said
above, you have the option of cross-posting to all relevant newsgroups,
including this one;
This is worst than the first one... because this time you actually shut
off any chance of redirection by your own rules (see ref1).
(2) It's been demonstrated multiple times on this
newsgroup that the experts are unlikely to correct one another's posts if
they happen to like one another. At least with multiple newsgroups there's
less chance of this happening, as can be seen in the healthy kinds of
debate that occur when threads cross newsgroup boundaries.
Killfiled?
A number of "established topicality" contradictions have been exposed, and
these contradictions have yet to be addressed. Every time these
contradictions have been raised, the topicality monitors suddenly go very
quiet. Why is that do you think? What does your gut tell you?
Maybe they *really* killfiled you?
The topicality monitors would better be served by creating comp.lang.c.iso
or comp.lang.iso-c and seeing how popular that becomes.
Wait, what? Why don't you do that? Call it net.lang.c.
This is not about topicality, this is about getting along and about
offering correct information and you don't seem to be particularly good
at neither. That's fine, we all make mistakes, but not all of us do
things just to spite others.