Created
April 16, 2011 15:23
-
-
Save tmiz/923190 to your computer and use it in GitHub Desktop.
n日後
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
struct mydate { int year,month,day; }; | |
int addDay(struct mydate *d, int n) | |
{ | |
struct tm birthday = {0,0,0,d->day,d->month,d->year-1900,0,0,0,0,NULL}; | |
time_t birthday_sec = mktime(&birthday); | |
birthday_sec += (n*24*60*60); | |
struct tm *pHA = localtime( &birthday_sec ); | |
if (pHA == NULL) return -1; | |
d->day = pHA->tm_mday; | |
d->month = pHA->tm_mon; | |
d->year = pHA->tm_year+1900; | |
return 0; | |
} | |
#ifdef _TEST | |
int main() { | |
struct mydate birthday = {2011,1,25}; | |
if (addDay(&birthday, 100) >= 0) { | |
printf("%d/%d/%d\n", birthday.year,birthday.month, birthday.day); | |
} | |
return 0; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment