Skip to content
Snippets Groups Projects
Select Git revision
  • 47fbe2beac25a805511f2dca459d67e1e6859c88
  • master default
2 results

incdate-6.c

Blame
  • Forked from Peter Gerwinski / hp
    362 commits behind the upstream repository.
    incdate-6.c 806 B
    #include <stdio.h>
    
    typedef struct
    {
      char day, month;
      int year;
    }
    date;
    
    void set_date (date *d)
    {
      d->day = 28;
      d->month = 2;
      d->year = 2012;
    }
    
    void inc_date (date *d)
    {
      d->day++;
      int days_in_month = 31;
      if (d->month == 2)
        {
          int is_leap_year = 1;  /* FIXME */
          if (is_leap_year)
            days_in_month = 29;
          else
            days_in_month = 28;
        }
      else if (d->month == 4 || d->month == 6 || d->month == 9 || d->month == 11)
        days_in_month = 30;
      if (d->day > days_in_month)
        {
          d->month++;
          d->day = 1;
          if (d->month > 12)
            {
              d->year++;
              d->month = 1;
            }
        }
    }
    
    int main (void)
    {
      date today;
      set_date (&today);
      inc_date (&today);
      printf ("%d.%d.%d\n", today.day, today.month, today.year);
      return 0;
    }