470,858 Members | 1,953 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,858 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){
  3. int month;
  4. time_t rawtime;
  5. struct tm timeinfo;
  7. timeinfo->tm_year = year;
  8. timeinfo->tm_mon = 2;
  9. timeinfo->tm_mday = 28;
  11. mktime(timeinfo);
  13. timeinfo = timeinfo + 86400;
  15. gmtime(timeinfo);
  17. month = timeinfo->tm_mon;
  19. return month;
Nov 23 '07 #1
1 3297
9,208 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
By using this site, you agree to our Privacy Policy and Terms of Use.