Check data in a structure - C Structure

C examples for Structure:Structure Definition

Description

Check data in a structure

Demo Code

#include <stdio.h>

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

struct date{/*from  w ww. j  a v a2s  .  c o  m*/
        int month;
        int day;
        int year;
    };


int main (void){
    struct date today, tomorrow;

    printf ("Enter today's data (mm dd yyyy): ");
    scanf ("%i%i%i", &today.month, &today.day, &today.year);

    if (today.day != daysPerMonth[today.month - 1]){
        tomorrow.day = today.day + 1;
        tomorrow.month = today.month;
        tomorrow.year = today.year;
    }
    else if (today.month == 12) // end of year
    {
        tomorrow.day = 1;
        tomorrow.month = 1;
        tomorrow.year = today.year + 1;
    }
    else                            // end of month
    {
        tomorrow.day = 1;
        tomorrow.month = today.month + 1;
        tomorrow.year = today.year;
    }

    printf ("Tomorrow's date is %i/%i/%.2i.\n", tomorrow.month, tomorrow.day, tomorrow.year % 100);
}

Result


Related Tutorials