LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 891|回复: 2

fputs函数一问

[复制链接]
发表于 2005-5-16 16:52:36 | 显示全部楼层 |阅读模式
#include <stdio.h>
代码:
#include <string.h>

int main(int argc,char **argv)
{
        FILE *fh;
        char buf[512];       

        fh = fopen("pap.txt", "r+");
         if (!fh)
         {
                 return 0;
         }       
               
         fputs( "why\n", fh );
         fclose(fh);
          return 0;
         
}
pap.txt文件存在内容如下:
# Secrets for authentication using PAP
# client        server        secret                        IP addresses
"root"        *        "666666"

程序编译通过,但执行后“why”字符串有时会出现并替代pap.txt文件的头几个字符串有时候却
不在文件里打印出来,不理解这是为什么?
另外我想自定义一行字符串替代pap.txt文件的第三行,请问该怎么做?
发表于 2005-5-16 17:21:50 | 显示全部楼层
我试过了。执行后“why\n"会替换文件前四个字符,并没有出现不在文件里打印出来的现象。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-16 17:48:30 | 显示全部楼层
真这样了,mad!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表