Skip to content

Instantly share code, notes, and snippets.

@schwern
Created March 4, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schwern/167e56de0c9d5e3aa33b to your computer and use it in GitHub Desktop.
Save schwern/167e56de0c9d5e3aa33b to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef struct date_t {
int year; int month; int day;
} date_t;
#define EPOCH 1970
void date_convert(date_t* date, unsigned int days) {
int year = EPOCH, mo = 0, day = 1;
while (days-- > 0)
{
// molen(), given a month and a year, returns the month's length
if (day++ > 30)
{
day = 1; mo++;
}
if (mo > 11)
{
mo = 0; year++;
}
}
date->year = year; date->month = mo; date->day = day;
}
int main() {
// date1 and date2 are of type date_t
unsigned int d1 = 10;
unsigned int d2 = 20;
unsigned int i;
date_t date;
for (i = d1; i <= d2; i++)
{
date_convert(&date, i); // The problem line
printf("%d, %d, %d\n", date.year, date.month, date.day);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment