C中的占位符,打印BOOL类型数据(3)

NSInteger i = 42;
printf("%ld\n", (long)i);

 

In addition to the considerations mentioned in Table 2, there is one extra case with scanning: you must distinguish the types for float and double. You should use %f for float, %lf for double. If you need to use scanf (or a variant thereof) with CGFloat, switch to double instead, and copy the double to CGFloat.

1
2
3
4

 

CGFloat imageWidth;
double tmp;
sscanf (str, "%lf", &tmp);
imageWidth =tmp;

 

It is important to remember that %lf does not represent CGFloat correctly on either 32- or 64-bit platforms. This is unlike %ld, which works for long in all cases.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6cb5d1d550014ee46f6104f41f7c3d30.html