Skip to content
Snippets Groups Projects
Select Git revision
  • f8790753f7d087fe3d84be9d0725cc6d75eb5da1
  • master default protected
  • 2018ws
  • 2017ws
  • 2016ws
5 results

functions-08.c

Blame
  • Forked from Peter Gerwinski / hp
    Source project has a limited visibility.
    incdate-8.c 860 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 = 2100;
    }
    
    void inc_date (date *d)
    {
      d->day++;
      int days_in_month = 31;
      if (d->month == 2)
        {
          int is_leap_year = 0;
          if (d->year % 4 == 0)
            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;
    }