struct tm Not returning anticipated value

Trying to understand the struct available in the time.h library, but I am unable to receive the anticipated value. I always get return 0 for tm_yday, and 1 for tm_sec.

What am I doing wrong?

1
2
3
4
5
6
7
8
9
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
    struct tm timer;
    printf("%d\n", timer.tm_yday);
    return EXIT_SUCCESS;
}
Last edited on
Your var timer has just random numbers - like any var you don't initialize.
To learn about date and time have a look here:
https://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c
http://zetcode.com/articles/cdatetime/
Last edited on
Topic archived. No new replies allowed.