PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 入门和基础知识 » printf("%s", str) vs. printf(str)
本页主题: printf("%s", str) vs. printf(str) 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

meiwang12363

该用户目前不在线
级别: 中级程序员
精华: 1
发帖: 1069
威望: 0 点
金钱: 0 PYMB
贡献值: 0 点
在线时间:8(小时)
注册时间:2007-04-26
最后登录:2007-09-04

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
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 [url=javascript:;]Linux[/url] 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]
顶端 Posted: 2007-08-20 09:18 | [楼 主]
PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 入门和基础知识

时:11-23 04:26 Copyright © 2006 phpwhy.com 权
ICP05060669

曳息 -