История изменений
Исправление makoven, (текущая версия) :
Однако все-же много строк писать приходится. Намедни писал функцию, возвращающую строку со временем:
char *get_time() {
static const int strlen = 20;
time_t now = time(NULL);
if ( -1 == now) return NULL;
struct tm *cal_now = localtime(&now);
if (NULL == cal_now) return NULL;
char *stime = malloc(strlen);
if (NULL == stime) return NULL;
if(0 == strftime(stime, strlen, "%H:%M:%S", cal_now)){
free(stime);
return NULL;
}
return stime;
}
Исходная версия makoven, :
Однако все-же много строк писать приходится. Намедни писал функцию, возвращающую строку со временем:
char *get_time() {
static const int strlen = 20;
time_t now = time(NULL);
if ( -1 == now) return NULL;
struct tm *cal_now = localtime(&now);
if (NULL == cal_now) return NULL;
char *stime = malloc(strlen);
if (NULL == stime) return NULL;
if(0 == strftime(stime, strlen, "%H:%M:%S", cal_now)){
free(stime);
return NULL;
}
return stime;
}