DaVinci said:
here are two expressions:
time_t now = time(NULL);
char* s = ctime(&now);
Actually, these are not expressions. They are
variable definitions with initializers; the initializers
are expressions.
how to make them to one expression.
such as:
char* s = ctime(&time(NULL)) ,but it is not right.
The argument to ctime() must be a pointer to a time_t
value. C can only point at stored values ("lvalues"), not
at the transient values produced by expressions ("rvalues").
That is, the result of time() is a perfectly legitimate value,
but you cannot form a pointer to it. You can store it in a
variable and point at the variable, but you cannot point to
the value "in flight" before it's stored.
This implies that the value of time() must be stored
somewhere before you can create a pointer to it and call
ctime().
Do what you're doing now. There's nothing wrong with it.