'time'함수와 'time.h'의 다른 함수를 사용하는 코드가 있는데 'time'은 매 시간마다 NULL을 반환합니다 (하하는 재미 있지만 'time'은 나에게 유용합니다. 그러한 방향으로주의를 기울이는 것)이 다시 실행됩니다. 어제 시작된 것만 큼 이상합니다. 비슷하지만 비슷한 기능의 이전 사용법은 (필자가 추가 한) 코드가 괜찮음을 입증했다.time.h에 정의 된 'time'함수가 NULL을 반환하는 이유는 무엇입니까?
#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);
}
}
'stdlib.h'는'EXIT_SUCCESS'하고 (심지어 C89)에'EXIT_FAILURE' 정의 자체를 가지고, 그들은 휴대용입니다. 그러나,'EXIT_SUCCESS'는 꽤 쓸모가 없습니다. – effeffe