Pejman Moghadam / C-programming

C - Enumeration constant

Public domain


#include <stdio.h>
int main()
{
    enum month_type { JAN = 1, FEB, MAR, APR, MAY, JUN,
        JUL, AUG, SEP, OCT, NOV, DEC };
    enum month_type month;

    fprintf(stdout, "Enter month number of current date : ");
    fscanf(stdin, "%d", &month);
    switch (month) {
    case JAN:
        fprintf(stdout, "January");
        break;
    case FEB:
        fprintf(stdout, "February");
        break;
    case MAR:
        fprintf(stdout, "March");
        break;
    case APR:
        fprintf(stdout, "April");
        break;
    case MAY:
        fprintf(stdout, "May");
        break;
    case JUN:
        fprintf(stdout, "June");
        break;
    case JUL:
        fprintf(stdout, "July");
        break;
    case AUG:
        fprintf(stdout, "August");
        break;
    case SEP:
        fprintf(stdout, "September");
        break;
    case OCT:
        fprintf(stdout, "October");
        break;
    case NOV:
        fprintf(stdout, "November");
        break;
    case DEC:
        fprintf(stdout, "December");
        break;
    default:
        fprintf(stdout, "%d is not a month number !!!", month);
    }
    return 0;
}

BY: Pejman Moghadam
TAG: c, enum
DATE: 2011-02-27 16:16:00


Pejman Moghadam / C-programming [ TXT ]