Initialize Structure Arrays - C Structure

C examples for Structure:Structure Value

Description

Initialize Structure Arrays

Demo Code

#include <stdio.h>

struct month{//from w w w  .j  a v a  2 s.  c  om
        int numberOfDays;
        char name[3];
};

int main (void){
    const struct month months[12] =
    {
            { 31, {'J', 'a', 'n'} },
            { 28, {'F', 'e', 'b'} },
            { 31, {'M', 'a', 'r'} },
            { 30, {'A', 'p', 'r'} },
            { 31, {'M', 'a', 'y'} },
            { 30, {'J', 'u', 'n'} },
            { 31, {'J', 'u', 'l'} },
            { 31, {'A', 'u', 'g'} },
            { 30, {'S', 'e', 'p'} },
            { 31, {'O', 'c', 't'} },
            { 30, {'N', 'o', 'v'} },
            { 31, {'D', 'e', 'c'} },
    };

    for (int i = 0; i < 12; ++i )
        printf (" %c%c%c          %i\n",months[i].name[0],months[i].name[1],months[i].name[2],months[i].numberOfDays);

    return 0;
}

Result


Related Tutorials