Struct tm now = error incomplete type


I understand everything in Chapter 10 Structs and am trying to get to the challenge. However when I typed in the authors example to get the time as a struct tm (from the book) I get an error for the statement struct tm now; XCode is saying "Variable has incomplete type ‘struct tm’ and I can go no further.

Any suggestions?

Thanks for the help!


Might you copy and paste your code that’s got the error (and the 5-or-so lines above and below it) so that we can see?

For bonus points, use the Code tags in your reply so that your pasted code gets properly formatted.


I am also getting implicit declaration function warnings (not errors) for ‘time’ and ‘localtime_r’.
I try to type everything from the book into XCode so that I can understand how it works, especially one that pertains to challenges.

Thank you for your help!

Here’s the code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char * argv[]) { long secondsSince1970 = time(NULL); printf("It has been %ld seconds since 1970.\n", secondsSince1970); struct tm now; localtime_r(&secondsSince1970, &now); printf("The time is %d:%d:%d\n", now.tm_hour, now.tm_min, now.tm_sec); return 0; }