Cで(現在の日付なしで)現在の時刻を取得したいのですが、主な問題は関数でそれをしたいときです。私がそれらを使用しないときは、何も問題ありません。なぜ私のコードが1時間しか表示されないのか、誰か教えてもらえますか? (添付の画像を見てください)。前もって感謝します。
#include <stdio.h>
#include <time.h>
#include <string.h>
char* get_time_string()
{
struct tm *tm;
time_t t;
char *str_time = (char *) malloc(100*sizeof(char));
t = time(NULL);
tm = localtime(&t);
strftime(str_time, sizeof(str_time), "%H:%M:%S", tm);
return str_time;
}
int main(int argc, char **argv)
{
char *t = get_time_string();
printf("%s\n", t);
return 0;
}