Tag: printf

下面的程序如何在C89模式下编译时输出“C89”,编译为C99模式时如何输出“C99”?

我从网上find了这个C程序: #include <stdio.h> int main(){ printf("C%d\n",(int)(90-(-4.5//**/ -4.5))); return 0; } 这个程序的有趣之处在于,它在C89模式下编译和运行时,会打印C89 ,当它编译并运行在C99模式下时,将打印C99 。 但我无法弄清楚这个程序是如何工作的。 你能解释一下printf的第二个参数在上面的程序中是如何工作的吗?

PHP sprintf转义%

我想要以下输出: 将从您的充值帐户中扣除27.59欧元的50%。 当我做这样的事情: $variablesArray[0] = '€'; $variablesArray[1] = 27.59; $stringWithVariables = 'About to deduct 50% of %s %s from your Top-Up account.'; echo vsprintf($stringWithVariables, $variablesArray); 但它给了我这个错误vsprintf() [function.vsprintf]: Too few arguments in …因为它认为%在50%也replace。 我如何逃避它?

fprintf,printf和sprintf之间的区别?

任何人都可以用简单的英语解释printf , fprintf和sprintf与例子之间的区别吗? 它在哪里? 在阅读“C中的文件处理”时,我对这三者之间真的感到困惑。

printf()和puts()在C中有什么区别?

我知道你可以使用printf()和puts()来打印。 我也可以看到printf()允许你插入variables并进行格式化。 puts()仅仅是printf()一个原始版本。 它应该用于每一个可能的printf()没有string插值?

为什么在PHP中使用sprintf函数?

我想了解更多关于PHP函数sprintf()的信息,但是php.net并没有帮到我,因为我还是很困惑,为什么要用它呢? 看看下面的例子。 为什么使用这个: $output = sprintf("Here is the result: %s for this date %s", $result, $date); 当这样做,并更容易写IMO: $output = 'Here is the result: ' .$result. ' for this date ' .$date; 我在这里错过了什么?

如何在C中打印“unsigned long”?

我永远不能理解如何在C中打印unsigned long数据types 假设unsigned_foo是一个unsigned long ,那么我试试: printf("%lu\n", unsigned_foo) printf("%du\n", unsigned_foo) printf("%ud\n", unsigned_foo) printf("%ll\n", unsigned_foo) printf("%ld\n", unsigned_foo) printf("%dl\n", unsigned_foo) 而他们都打印某种-123123123号码,而不是unsigned long ,我有。

什么是布尔的printf格式说明符?

由于ANSI C99通过stdbool.h有_Bool或bool 。 但是,还有一个printf格式说明符的布尔? 我的意思是像这样的伪代码: bool x = true; printf("%B\n", x); 这将打印: true

在printf中修正double的格式说明符

printf中double的正确格式说明符是什么? 是%f还是%lf ? 我相信它的%f但我不确定。 代码示例 #include <stdio.h> int main() { double d =1.4; printf("%lf", d); //is this wrong? }

什么是printf的格式很长的参数?

printf函数采用参数types,例如%d或%i作为signed int 。 但是,我没有看到任何long价值。

pthread:一个printf语句在子线程中打印两次

这是我的第一个pthread程序,我不知道为什么printf语句在子线程中打印两次: int x = 1; void *func(void *p) { x = x + 1; printf("tid %ld: x is %d\n", pthread_self(), x); return NULL; } int main(void) { pthread_t tid; pthread_create(&tid, NULL, func, NULL); printf("main thread: %ld\n", pthread_self()); func(NULL); } 在我的平台上观察输出(Linux 3.2.0-32-generic#51-Ubuntu SMP x86_64 GNU / Linux): 1. main thread: 140144423188224 tid 140144423188224: x is 2 […]