回覆列表
  • 1 # 程式設計頌

    struct tm st1, st2 使用前沒有初始化

    GNU 手冊上關於 strptime 提示寫到:

    In principle, this function (strptime) does not initialize tm but only stores the values speci‐

    fied. This means that tm should be initialized before the call. Details differ a

    bit between different UNIX systems. The glibc implementation does not touch those

    fields which are not explicitly specified, except that it recomputes the tm_wday and

    tm_yday field if any of the year, month, or day elements changed.

    time_t t1= 0;

    errno = 0;

    printf("%s\n", date);

    +

    + memset( &st1, 0, sizeof( st1 ) );

    + memset( &st2, 0, sizeof( st2 ) );

    +

    if (NULL == strptime(date, "%Y%m%d", &st1))

    {

    perror("strptime error");

    得到結果

    20140228

    __1393516800

    20140301

    20140301

  • 中秋節和大豐收的關聯?
  • 地理中的寒流和暖流是什麼?