printf("C programming %s","is %s for health","good");

时间:2018-02-26 17:47:16

标签: c

#include<stdio.h>
int main()
{
 printf("C programming %s","is %s for health","good");
return 0;
}

is this a way to print c programming is good for health. as of my idea first "is %s for health","good" will render then "c programming %s", is good for health".

4 个答案:

答案 0 :(得分:2)

#include<stdio.h>
int main()
{
 printf("C programming is %s for health","good");
 printf("C programming is good for health");
return 0;
}

you can simply write it like any of the way in this code. but the way you wrote is wrong because it only the first argument of printf() can use %s. all other arguments act as simple strings

答案 1 :(得分:1)

#include<stdio.h>
int main()
{
    char *good= "good";
    char *health = "health";
    printf("C programming is %s for %s", health, good);

    printf("C programming is %s for %s", good, health);
    return 0;
}

答案 2 :(得分:1)

If you insist on 2 arguments then use %s for string twice.

#include<stdio.h>
int main()
{
    printf("C programming %s%s","is good" ," for health");
    return 0;
}

Output:

C programming is good for health

答案 3 :(得分:0)

printf不起作用 - 只处理第一个参数以识别转换说明符,其余参数的格式也相应。

这意味着%s中的"is %s for the health"未被识别为转化说明符 - 它只被识别为字符串的一部分。这也意味着忽略了最终的"good"参数。

TL / DR; - 您不能像C中那样“链接”格式化字符串。

BTW - C编程对您的健康有益。相信我。