10/25 Simple question.. In C under unix, how do I invoke the unix command
date to create a char string which contains the present date?
\_ actually, you should fork a process that runs date
but has date's stdout handle to point to a handle in the
parent proc. yeah, you really want time(), ctime()
\_ could I get an example .. something like :
current_date = ctime(); ??
\_ Here you go:
char * my_date;
time_t my_time;
time(&my_time);
my_date = ctime(&my_time);
See the manpages for time(3) and ctime(3).
\_ try both. find the source for date(1) and examine it. --jon
\_ system("date"), but you really want time(), ctime()
\_ actually, you should fork a process that runs date
but has date's stdout handle to point to a handle in the
parent proc. yeah, you really want time(), ctime()
\_ could I get an example .. something like :
current_date = ctime(); ??
\_ Here you go:
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv) {
char * my_date;
time_t my_time;
time(&my_time);
my_date = ctime(&my_time);
printf("%s",my_date);
exit(0);
}
See the manpages for time(3) and ctime(3).
\_ try both. find the source for date(1) and examine it. --jon |