shell - how to invoke system() for date command in C -
i have been trying invoke library function system() call date in c program
it's not displaying output.
int main() { char cmd[20]; strcpy(cmd, "date"); system(cmd); return(0); }
use gettimeofday() date time or whatever . example :
#include <sys/time.h> #include <time.h> #include <stdlib.h> #include <stdio.h> int main(void) { char buffer[30]; struct timeval tv; time_t curtime; gettimeofday(&tv, null); curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%y %t.",localtime(&curtime)); printf("%s%ld\n",buffer,tv.tv_usec); return 0; }
Comments
Post a Comment