Reputation: 57357
I'm still very new to C and trying to learn how to use strptime to see if it will work for part of a project, but I can't even get what seems like a very basic example working right...
int main()
{
struct tm *t;
t = (struct tm *) malloc(sizeof(struct tm));
memset(t, 0, sizeof(t));
if (strptime("12-2009", "%m-%Y", t) != NULL)
printf("month: %d year: %d\n",t->tm_mon, t->tm_year);
free(t);
return 0;
}
Running this program gives: "month: 11 year: 109"
What am I missing here??
Upvotes: 1
Views: 312
Reputation: 190907
Its Y2K!
Add 1900 to the year. The months are 0 indexed.
Upvotes: 4