Concatenating string and char literals in C

122 views Asked by At

In my code I define some compiler constants such as the following:

#define D_CR  '\x10'    // New line
#define D_LF  '\x13'    // New paragraph
#define D_EOS '\xFF'    // End of string

(these could be chars, ints, whatever ... )

And I want to use them in two ways, one in a string literal, and secondly in switch statements.

unsigned char dialogString[] = 
    "LOREM IMSUM" D_CR
    "DOLAR SIT A MET" D_EOS;

switch (dialogString[i]) {
    case D_CR: /* ... */ break;
    case D_LF: /* ... */ break;
    case D_EOS: /* ... */ break;
    default: printf(dialogString[i]); break;
}

The problem that I'm getting is that I'm mixing types and I'm getting compiler warnings.

dialogString.c(5) parse error: token -> ''\x10'' ; column 11

Is there any way that I can get this to work for both scenarios?

0

There are 0 answers