它的简单代码。
它不应该打印:( null)。
应该是:Mon Jul 31 14:33:39 2017
为什么要打印:( null)?
#include "stdafx.h"
#include <time.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
time_t currentTime;
char c_time_string[26];
currentTime = time(NULL);
if (currentTime == (time_t)-1 )
{
(void)fprintf(stderr, "Failure to obtain the current time. \n");
exit(EXIT_FAILURE);
}
ctime_s(c_time_string, 26, ¤tTime);
if ( c_time_string == NULL)
{
(void)fprintf(stderr, "Failure to obtain the current time. \n");
exit(EXIT_FAILURE);
}
(void)printf("a: %d \n a:%s \n", currentTime, c_time_string);
(void)printf("b: %s", c_time_string);
getchar();
}
答案 0 :(得分:0)