我做了同样的" printf",但结果出来了

时间:2017-07-31 23:55:05

标签: c

它的简单代码。

它不应该打印:( 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, &currentTime);
        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();
}

enter image description here

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。看评论。有答案