Re: [Dev-C++] How to copy ctime(timer);
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alfred P. R. <al...@ya...> - 2005-04-25 05:03:29
|
Hi Letchumanan,
Lets see... My suggestions are:
data.time must be char* or char time[26], as ctime returns a pointer to a block of exactly 26 characters.
If you use time_t timer instead of *timer, then you don't have to malloc it. time_t is just a long integer. Also see time, "The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored." So you could do strncpy( data.time, ctime( time(NULL) ) ); and loose the variable timer altogether unless you need to save it for some reason.
Don't use time as a variable name as it also is a function name. This is just for clarity rather than for functionality. Instead use time_str or some such descriptive nomenclature.
Have a great week, Letchumanan!
LETCHUMANAN SAMINADAN <arl...@ya...> wrote:
Dear all,
Is it possible for me to copy current time. I have a problem on this.... Can some one please help me. My coding as below:-
char * ctime(const time_t *timer);
struct record {
char pass[10],name[15],ptname[30],ptnum[30],cust,time,utl_1;
float pqty,gweight,nweight,thick,width,pitch,density,raw,fin, //variable used
mtused,in,out,xpqty,lossa,lossb,lost,start,stop,hour,utl;
} data;
void addData () {
time_t *timer;
timer = malloc(sizeof(time_t));
*timer = time(NULL); //return system time
strncpy(data.time,ctime(timer));
printf("DATE/TIME : %s", data.time);
printf("-------------------------------------\n");
}
Thank you,
Letchu.....
Alfred P. Reaud
|