简体   繁体   English

目标C语法错误

[英]Objective C Syntax Error

printf("%f A ball with a radius of 14.5 inches."); printf(“%f一个半径为14.5英寸的球。”);

How do I correct this? 我该如何纠正? I am trying to write a print function(Still pretty green when it comes to C) I am not sure how to correct it. 我正在尝试编写一个打印功能(当涉及到C时,它仍然很绿)我不确定如何纠正它。

You may or may not be receiving a compilation warning with this because you are calling printf, have a specifier in your format, but do not provide a value. 您可能会或可能不会收到与此相关的编译警告,因为您正在调用printf,格式中有一个指定符,但未提供值。 "%f" expects for you to pass a float value to it. “%f”期望您将浮点值传递给它。 The following: 下列:

printf("A ball with radius of %f inches.", 14.5f); 

should work, if that is what you are looking to do. 如果您要这样做的话,它应该可以工作。 If it is, you might need to augment the %f to adjust for precision (something like "%.1f" ). 如果是这样,则可能需要增加%f以调整精度(类似于"%.1f" )。

Otherwise if you actually want to print the %f outright try this: 否则,如果您实际上要直接打印%f,请尝试以下操作:

printf("%%f A ball with a radius of 14.5 inches.");

Happy coding! 编码愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM