I want to get current time (without a current date) in C. The main problem is when I want to do it with functions. When I dont use them, evertyhing is just fine. Can anybody tell me, why my code shows only an hour? (take a look at the attached image). Thanks in advance.
struct tm *tm;
char *str_time = (char *) malloc(100*sizeof(char));
t = time(NULL);
tm = localtime(&t);
strftime(str_time, sizeof(str_time), "%H:%M:%S", tm);
int main(int argc, char **argv)
char *t = get_time_string();
sizeof operator returns the length of the variable
str_time which is a pointer to char. It doesn't returns the length of your dynamic array.
100 and it will go fine.