Re_Kotc
15-02-2007, 11:35
sto cercando di stampare a video l'ora di sistema..ovviamente usando il C, su internet ho trovato questo :
char *ctime(time_t *ptr)
char *ctime_r(time_t *ptr, char *output)
include: <time.h>
Note that the parameter must be a pointer to the numeric time.
time_t values are produced by time.
Converts the time provided into a human-readable string, the format
is illustrated by these examples:
Mon Jan 18 22:14:07 2038\n
Fri Jan 8 12:14:07 2038\n
Mon Jan 18 08:20:37 2038\n
Fri Dec 13 15:45:52 1901\n
Dates are padded with a space if only one digit long, and time components
are given leading zeros. The date is always absurdly followed by a
newline character, which usually has to be removed.
Warning the char* string returned is a static array, every call
of ctime uses the same array, so the results of any call are always
overwritten by the bext call.
Ctime_r is exactly the same as ctime, except that the caller must provide
an array of chars big enough to hold the result. The return value is the
same as the second parameter.
l'esempio che mostra è il seguente..ma non funziona almeno sul mio compilatore, mi dice "`strlen' cannot be used as a function"
ammetto che ho capito poco di come stampa l'ora questa funzione ma speravo di cavarmela con l'esempio..mi sapete dire qualcosa? grazie
Example:
time_t tim=time(NULL);
char *s=ctime(&tim);
s[strlen(s)-1]=0; // remove \n
printf("it is %s now.\n", s);
time_t values are produced from the clock by time.
time_t values are produced from y,m,d,h,m,s parts by mktime and timegm.
char *ctime(time_t *ptr)
char *ctime_r(time_t *ptr, char *output)
include: <time.h>
Note that the parameter must be a pointer to the numeric time.
time_t values are produced by time.
Converts the time provided into a human-readable string, the format
is illustrated by these examples:
Mon Jan 18 22:14:07 2038\n
Fri Jan 8 12:14:07 2038\n
Mon Jan 18 08:20:37 2038\n
Fri Dec 13 15:45:52 1901\n
Dates are padded with a space if only one digit long, and time components
are given leading zeros. The date is always absurdly followed by a
newline character, which usually has to be removed.
Warning the char* string returned is a static array, every call
of ctime uses the same array, so the results of any call are always
overwritten by the bext call.
Ctime_r is exactly the same as ctime, except that the caller must provide
an array of chars big enough to hold the result. The return value is the
same as the second parameter.
l'esempio che mostra è il seguente..ma non funziona almeno sul mio compilatore, mi dice "`strlen' cannot be used as a function"
ammetto che ho capito poco di come stampa l'ora questa funzione ma speravo di cavarmela con l'esempio..mi sapete dire qualcosa? grazie
Example:
time_t tim=time(NULL);
char *s=ctime(&tim);
s[strlen(s)-1]=0; // remove \n
printf("it is %s now.\n", s);
time_t values are produced from the clock by time.
time_t values are produced from y,m,d,h,m,s parts by mktime and timegm.