#include <stdio.h>
#include <stdlib.h>

#define BUFFSZ 32

const int DAYS_IN_MONTH[12] = {
    31,
    28,
    31,
    30,
    31,
    30,
    31,
    31,
    30,
    31,
    30,
    31
};

void increment_date(int *year, int *month, int *day) {
    (*day)++;
    
    if (*day > DAYS_IN_MONTH[*month - 1]) {
        *day = 1;
        (*month)++;
    }

    if (*month > 12) {
        *month = 1;
        (*year)++;
    }
}

void decrement_date(int *year, int *month, int *day) {
    (*day)--;
    
    if (*day < 1) {
        (*month)--;
        if (*month < 1) {
            *month = 12;
            (*year)--;
        }
        *day = DAYS_IN_MONTH[*month - 1];
    }
}

int main(void) {
    char *buff = (char*)malloc(sizeof(char) * BUFFSZ);

    int m, d, y;
    printf("Input date in mm/dd/yyyy: ");
    fgets(buff, BUFFSZ, stdin);
    sscanf(buff, "%d/%d/%d", &m, &d, &y);


    char opr_in;
    while (1) {
        printf("Select operation [+/-]: ");
        opr_in = getc(stdin);
        if (opr_in == '+') {
            increment_date(&y, &m, &d);
            printf("Tomorrow is %02d/%02d/%4d\n", m, d, y);
            break;
        } else if (opr_in == '-') {
            decrement_date(&y, &m, &d);
            printf("Yesterday was %02d/%02d/%4d\n", m, d, y);
            break;
        } else {
            printf("Error: Please input correct operation mode.\n");
        }
    }


    return 0;
}
