我正在尝试将输出生成为双引号输入。例如,如果在 str() 中传递的参数是某个 name,那么输出应该是 "name",这在下面的代码中不会发生。
#include<stdio.h>
#include<string.h>
#define str(s) #s
#define newline printf("\n")
int main()
{
printf("Your double quoted code is : %s ",str(GHOST));
newline;
}
Output : GHOST
最佳答案
发生的事情是添加了引号,但它们作为语言语法的一部分被使用了。因为,您需要向 printf
传递一个字符串,例如 "GHOST"
,而不仅仅是一个标识符。
如果你想在运行程序时出现引号,我会做到
printf("Your double quoted code is : \"%s\" ",str(GHOST));
相反。格式字符串中的转义引号将出现在输出中。
关于c - C 中宏的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32448546/