M
Materialised
I am having a problem with the following functions, I've been racking my
brains trying to figure out where I am going wrong. What I need to do is
return a formatted string with the current date and time in the format of:
[Thu May 5 17:06:27 2005]
Here is my function as it stands:
char *currenttime(){
char *curtime;
time_t t;
char *p, *e;
t = time(NULL);
p = ctime(&t);
if (p && ((e = strchr(p, '\n')))) *e = '\0';
curtime = malloc(strlen(p)+2);
if(curtime == NULL) {
printf("out of memory\n");
exit(1);
}
snprintf(curtime, sizeof(curtime+2), "%c%s%c", '[', p, ']');
printf("%s\n", curtime);
return curtime;
}
I hope someone can help me.
--
Materialised
perl -e 'printf %silto%c%sal%c%s%ccodegurus%corg%c, ma, 58, mw, 107,
'er', 64, 46, 10;'
Bart: "What's Santa's Little Helper doing to that dog? Looks like he's
trying to jump over, but he can't quite make it."
brains trying to figure out where I am going wrong. What I need to do is
return a formatted string with the current date and time in the format of:
[Thu May 5 17:06:27 2005]
Here is my function as it stands:
char *currenttime(){
char *curtime;
time_t t;
char *p, *e;
t = time(NULL);
p = ctime(&t);
if (p && ((e = strchr(p, '\n')))) *e = '\0';
curtime = malloc(strlen(p)+2);
if(curtime == NULL) {
printf("out of memory\n");
exit(1);
}
snprintf(curtime, sizeof(curtime+2), "%c%s%c", '[', p, ']');
printf("%s\n", curtime);
return curtime;
}
I hope someone can help me.
--
Materialised
perl -e 'printf %silto%c%sal%c%s%ccodegurus%corg%c, ma, 58, mw, 107,
'er', 64, 46, 10;'
Bart: "What's Santa's Little Helper doing to that dog? Looks like he's
trying to jump over, but he can't quite make it."