以下语句在C中正确吗?
printf(" the string is %s", printf("xyz"));
我的意思是,是否可以在
printf
函数中使用1个printf
语句?如果可能的话,请发送该表达式的正确语法。
最佳答案
printf
返回打印的字符数,因此当您的formatstring尝试打印字符串时,上述声明将是错误的。
您可以这样做:
printf("characters printed: %d", printf("xyz"));
如果要输出格式化字符串的结果,则必须先使用
snprintf
,然后将其打印到数组中,然后可以使用数组将其打印为字符串。例:
char s[100];
snprint(s, sizeof(s), "My string %d", 3);
printf(" the string is %s", s);
关于c - 我们可以在C语言的printf()函数中使用printf语句吗,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21228274/