This is the faulty 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 it gives that error? How could I fix it?
EDIT
This is what I am 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);
The result of ##
must be a single token, and "HELLO""WORLD"
is not a single token. To concatenate strings, simply leave them beside each other:
printf("HELLO" "WORLD");
Or change your macro to remove the ##
.
#define CAT(A, B) A B
String literals are concatenated together when there are no intervening tokens between them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With