打印

printf("%s", str) vs. printf(str)

printf("%s", str) vs. printf(str)

printf("%s", str) vs. printf(str)

Created: Fang lungang 03-08-2007Modified: Fang lungang 03-08-2007 21:35>

The C Programming Language 2nd 看到的 printf 一个需要注意的细节:即使被打印的本身就只有一个字符串,最好也别直接打印,而要用格式符 %s。其它格式输出的函数应该也类似。

#include <stdio.h>

int main()
{
char* str= "a string with % may not workn";
printf ("%s", str);
printf (str);
return 0;
}
[/home/lungangfang/tmp]gcc --version
gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[/home/lungangfang/tmp]./a.out
a string with % may not work
a string with Successay not work
[/home/lungangfang/tmp]

TOP

当前时区 GMT-4, 现在时间是 2008-11-20 14:53
ComePlay8.Com
Powered by Discuz! 6.0.0 © 2001-2007 Comsenz Inc.
Processed in 0.062380 second(s), 10 queries, Gzip enabled
TOP
清除 Cookies - 联系我们 - 来玩吧 - Archiver - WAP
Designed By Discuz! Support Team