Define escape in enum, use enum to control for loop - C Data Type

C examples for Data Type:enum

Description

Define escape in enum, use enum to control for loop

Demo Code

#include <stdio.h>
enum escapes { BELL = '\a', BACKSPACE = '\b', TAB = '\t',
               NEWLINE = '\n', VTAB = '\v', RETURN = '\r' };

enum months { JAN = 1, FEB, MAR, APR, MAY, JUN,
              JUL, AUG, SEP, OCT, NOV, DEC };
                    /* FEB is 2, MAR is 3, etc. */


int main() {/*from  w  ww.ja va 2s  . com*/
    printf("BELL, BACKSPACE, TAB, NEWLINE, VTAB, RETURN\n");
    
    printf("%o %o %o %o %o %o\n",BELL, BACKSPACE, TAB, NEWLINE, VTAB, RETURN);
        
    for (int i = JAN; i <= DEC; i++)
        printf("%d ", i);
    
    printf("\n");
    
    return 0;
}

Result


Related Tutorials