Using #if, #elif, and #else

Thursday, November 13, 2014
/* 2303.c: Using #if, #elif, and #else */
#include <stdio.h>

#define C_LANG 'C'
#define B_LANG 'B'
#define NO_ERROR 0

main(void)
{
    #if C_LANG == 'C' && B_LANG == 'B'
        #undef C_LANG
        #define C_LANG "I know the C language.\n"
        #undef B_LANG
        #define B_LANG "I know BASIC.\n"
        printf("%s %s", C_LANG, B_LANG);
    #elif C_LANG == 'C'
        #undef C_LANG
        #define C_LANG "I only know C language.\n"
        printf("%s", C_LANG);
    #elif B_LANG == 'B'
        #undef B_LANG
        #define B_LANG "I only know BASIC.\n"
        printf("%s", B_LANG);
    #else
        printf("I don't know C or BASIC.\n");
    #endif

    return NO_ERROR;
}

Copyright @ 2015 Tron!

Labels