468,512 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Using mktime()

Hey I was wondering if anyone could help me with some time code that I am using to determine if a year is a leap year or not. The code I have takes a given year, creates a time structure of the given year, and sets the date to 28th of Febuary, I then need to convert it using mktime(), add the amount of time to move to the next day, then reconvert it in order to take the month and determine whether it is a leap year or not by whether the month is Febuary of March. I have done the following code and have added and changed it several times, however, I cannot get it to work, any help would be much appreciated.


Expand|Select|Wrap|Line Numbers
  1. int isLibLeap(int year){
  2.  
  3. int month;
  4. time_t rawtime;
  5. struct tm timeinfo;
  6.  
  7. timeinfo->tm_year = year;
  8. timeinfo->tm_mon = 2;
  9. timeinfo->tm_mday = 28;
  10.  
  11. mktime(timeinfo);
  12.  
  13. timeinfo = timeinfo + 86400;
  14.  
  15. gmtime(timeinfo);
  16.  
  17. month = timeinfo->tm_mon;
  18.  
  19. return month;
Nov 23 '07 #1
1 3226
weaknessforcats
9,207 Expert Mod 8TB
mktime() takes a struct tm argument and returns a time_t.

It is that time_t that you add the 86400 to and not the struct tm.

Then you use the time_t as the argument for gmtime to get the equivalent struct tm back.

Your code doesn't do that.

In fact, your code won't even compile.

Start with your first compiler error and fix that. Then rebuild. Then fix the first error, then rebuild, etc.

When you have no compile errors, your code will probably work.
Nov 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Bengt Richter | last post: by
2 posts views Thread by Florian Quetting | last post: by
4 posts views Thread by McBooCzech | last post: by
16 posts views Thread by John Hanley | last post: by
2 posts views Thread by John Hanley | last post: by
5 posts views Thread by Robert Latest | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.