Insert error "HELLO" "and" WORLD "" does not give a valid preprocessing token
This is a bad code.
#include<stdio.h> #define CAT_I(A, B) A ## B #define CAT(A, B) CAT_I(A,B) void main (void) { printf(CAT("HELLO","WORLD")); } Why does this give this error? How can i fix this?
EDIT
This is what I'm trying to do.
#define TAG "TAG" #define PRE CAT(CAT("<",TAG),">") #define POS CAT(CAT("</",TAG),">") #define XML CAT(CAT(PRE,"XML SOMETHING"),POS) then
printf(XML); Result ## must be one token, and "HELLO""WORLD" - not one token. To concatenate the lines, just leave them next to each other:
printf("HELLO" "WORLD"); Or change your macro to remove ## .
#define CAT(A, B) AB String literals are combined together when there are no intermediate tokens between them.