Use popen to read the output of the command. Remember to close the stream with pclose .
FILE *f = popen("date", "r"); fgets(array, sizeof(array), f); pclose(f);
But instead of running an external program, you can use localtime and strftime .
time_t t = time(0); struct tm lt; localtime_r(&t, <); strftime(array, sizeof(array), "%a %b %d &T %z %Y", <);
ctime is similar, but does not include the time zone.
ctime_r(&t, array);
source share