Hello every one.I coded a program to print current date and time.
First I declare a function tim() to calculate the current time.
It works well.But the problem is I cant call the function from main() function.It doesnt print any thing.What is wrong with this code?
Please help me.Thanks very much!
here is my code.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char* tim()
{
struct tm *d;
time_t now;
char li[50];
char* temp;
time(&now);
d=localtime(&now);
memset(li,'\0',sizeof(li));
strftime(li,50,"%Y.%m.%d.%H.%M.%S",d);
temp =li;
// printf("time now:%s\n",temp);
return temp;
}
int main()
{
char* array;
array=tim();
printf("Time:%s\n",array);
}