I want to get timestamp for my log in c. i have written a function to get timestamp. But when i return the variable i m getting different value.
My code:
<
You are returning a pointer to a stack variable and therefore it is not valid to use after the function returns:
char buffer[16];
Will be allocated on the stack in the function. When you return the stack is cleaned up and buffer
is no longer valid. With minimal changes this is probably a better function signature:
void get_timestamp( char *buffer, size_t buffLen )
The assumption being that you have properly allocated space for buffer
before calling get_timestamp
.