I have my function print_date_time
which I want to return the date as a string. I then want to assign that time to a new variable and print it in main
. After that, I want to use it in another function.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>
#include <time.h>
#include <assert.h>
static char* print_date_time()
{
time_t t = time(NULL);
struct tm* tm = localtime(&t);
char s[64];
assert(strftime(s, sizeof(s), "%c", tm));
//printf("TIME TIME: %s\n", s);
return s;
}
/****************************************
*
* MAIN FUNCTION
*
****************************************/
int main(int argc, char** argv)
{
char *date;
date = print_date_time();
printf("time is: %s\n",date);
//assert(strftime(tab, sizeof(tab), "%c", print_date_time()));
//print_date_time();
return 0;
}
I expect the current time.
How do I get a string from a function and assign to it?