我的代码使用了函数 'time' 和来自 'time.h' 的其他函数,并且 'time' 每次'time' 都返回 NULL (哈哈,虽然不好笑,但这对于我可以集中精力的 'time' 来说是很昂贵的对此类的关注)此类被重新执行。奇怪的是,这只是昨天才开始的。以前在类似但缺少(我一直在添加)代码中使用相同的功能证明是可以的。以下是C89代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
typedef struct tm tm;
int logf(char input_string[])
{
time_t* current_time_since_epoch;
time(current_time_since_epoch);
if (current_time_since_epoch == NULL)
{
printf("'time' returned NULL.\n");
return EXIT_FAILURE;
}
tm* current_time_calandar_time = localtime(current_time_since_epoch);
if (current_time_calandar_time == NULL)
{
printf("'localtime' returned NULL.\n");
return EXIT_FAILURE;
}
char current_time_textual_representation[20];
strftime(current_time_textual_representation, 20, "%d-%m-%Y %H:%M:%S", current_time_calandar_time);
printf("%s\n", current_time_textual_representation);
printf("%s\n", input_string);
return EXIT_SUCCESS;
}
int main(void)
{
int check_logf = logf("Hello.");
if (check_logf == 0) exit(EXIT_SUCCESS);
else
{
printf("'logf' returned EXIT_FAILURE.\n");
exit(EXIT_FAILURE);
}
}