Thursday, April 21, 2011

strptime returning unexpected results

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??

From stackoverflow
  • Its Y2K!

    Add 1900 to the year. The months are 0 indexed.

    bcasp : Wow...the sound of my palm hitting my face could probably be heard for miles...thanks for the quick response

0 comments:

Post a Comment