Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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