I want to put the output of GNU/Linux date command in a character array.
Example:
char array[25];
$ date
Thu Jul 19 09:21:31 IST 2012
printf("%s", array);
/* Should display "Thu Jul 19 09:21:31 IST 2012" */
I tried this:
#include <stdio.h>
#include <string.h>
#define SIZE 50
int main()
{
char array[SIZE];
sprintf(array, "%s", system("date"));
printf("\nGot this: %s\n", array);
return 0;
}
But the output shows NULL in the array.