加载中…
个人资料
bluemonster
bluemonster
  • 博客等级:
  • 博客积分:0
  • 博客访问:0
  • 关注人气:0
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:大 中 小

C语言写一行及写换行符的问题

(2010-08-08 09:05:22)
标签:

c

换行

写文件

一行

it

分类: 实验室
int fputs( const char *str, FILE *stream );
将str中的字符串拷贝到stream的当前位置,str字符串最后的null终止字符(如果有的话)并不会被拷贝进去。
至于换行符,msdn介绍fwrite时说了:
size_t fwrite(
   const void *buffer,
   size_t size,
   size_t count,
   FILE *stream 
);
The fwrite function writes up to count items, of size length each, from buffer to the output stream. The file pointer associated with stream (if there is one) is incremented by the number of bytes actually written. If stream is opened in text mode, each carriage return is replaced with a carriage-return – linefeed pair. The replacement has no effect on the return value.

This function locks the calling thread and is therefore thread-safe. For a non-locking version, see _fwrite_nolock.

如果stream是以文本方式打开的,那么str中的\r会被自动替换为\r\n写入stream。但是str本身的\r并没有被替换为\r\n,因此返回值中\r还是算写了一个字符。

0

阅读┊ 收藏 ┊ 喜欢▼ ┊打印┊举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有