读书人

超简单的define,居然不会写,该如何处理

发布时间: 2012-02-21 16:26:23 作者: rapoo

超简单的define,居然不会写
#define HELLO(x) \
"hello world(x) " \
" (x) is a fool; "

int main()
{
char *c = HELLO( "blue ");
printf( "%s ",c);
我期望输出 "hello world blue blue is a fool; "
}
如何搞?

[解决办法]
#define HELLO(x) "hello world " x " " x " is a fool; "
[解决办法]
#define HELLO(x) "hello world " x " " x " is a fool; "

"hello world " <==> "hello " " world "
[解决办法]
#include <stdio.h>

#define HELLO(x) "hello world "##x## " "##x## " is a fool; "

int main()
{
char *c = HELLO( "blue ");
printf( "%s\n ",c);

return (0);
}

读书人网 >C语言

热点推荐