printf("s", str) vs. print...
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]
制作:罗可龙 电邮:luokelong(at)it168.com