#include <stdio.h>
#include <time.h>
int main ()
{
time_t time_raw_format;
struct tm * ptr_time;
char *buff;
time ( &time_raw_format);
ptr_time = localtime ( &time_raw_format );
}
How to copy this to a *buff, return type of ptr_time is struct tm*,my actual goal is to copy system date and time to a char buffer and how to calculate the size returned by localtime, as *ptr_time is a pointer if I do sizeof that i get the value as 4
You can format the time into a char buffer with
strftime()ptr_timeis a pointer,*ptr_timeis dereferencing a pointer.sizeof(ptr_time)gives the value 4, on a 32 bit system. The size ofstruct tmis eithersizeof(struct tm)orsizeof(*ptr_time), which gives the size of whatever the pointer points to.