使用C

时间:2016-03-29 06:50:41

标签: c printf double

我试图将三个printf语句转换成一个更长的语句,用C. 我想转:

printf("The current system time is ");
printf("%f", get_current_time());
printf("\n");

到单个printf语句中,其中函数get_current_time返回double,例如1459231814.421397或类似名称。 我设法得到的最接近的是

printf("The current system time is " , ("%f" (get_current_time())), "\n");

只返回一个错误,即:

error: called object is not a function or function pointer

printf("The current system time is " , ("%f" (get_current_time())), "\n");"

并指出"之前的%f

三个单独的printf语句打印:

"The current system time is 1459231876.947026"

或类似的设定次数,每次都在新的一行,这就是我想要的。

我不明白为什么它在分离时有效,但将它们一起添加到一个长语句中就会失败。我确定我必须错误地格式化较长的陈述,只是不确定我做错了什么。 非常感谢任何帮助,如果这个问题的格式不是很好,我很抱歉,这是我提出的第一个问题。

5 个答案:

答案 0 :(得分:1)

不确定为什么没有人提到这一点,但是:

printf("The current system time is %f\n", get_current_time());

答案 1 :(得分:1)

printf("The current system time is %f \n",get_current_time());

答案 2 :(得分:1)

使用以下内容:

printf ( "The current system time is %f\n", get_current_time() );

答案 3 :(得分:0)

这是printf

的基本用例
printf("%s%f\n", "The current system time is ", get_current_time());

答案 4 :(得分:0)

你想要的是:

printf("%s%f\n", "The current system time is ", get_current_time());

printf("The current system time is %f\n", get_current_time());
相关问题