fread函数读取文件提前结束
来源:互联网 发布:慢动作视频软件 编辑:程序博客网 时间:2024/06/09 19:57
最近写了一个读unicode文本的函数,是用fread函数读,但有时候不能读完,后来网上查了下,见下文:
最近写一个程序,发现用fread读“.dat”文件时不能读完整个文件,后来用hex格式观察读文件退出位置的数字,才发现只要是读到0x1A时,fread就认为结束!后来看了MSDN后知道用text模式打开文件时,系统默认CTRL+Z为文件结束符,而0x1A刚好就是CTRL+Z的ASCII码。另外在另一个文章里面说到如果遇到“/r/n”,也将被映射为“/n”。因此如果是读普通数据而非文本,以以下格式打开文件。
datafile = fopen("whatever.dat", "rb"); 这样就可以解决以上问题!
在MSDN中,对于"t"和"b"打开模式的原文如下:
Also, in text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function).
If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL.
原文地址
- fread函数读取文件提前结束
- fread读取文件注意
- fread 读取文件问题
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- fread读取ASCII编码文件
- fread读取Unicode编码文件
- fread读取文件(二进制文件)
- C语言fread()函数:读文件函数(从文件流读取数据)
- org.dom4j.DocumentException 文件提前结束。 Nested exception 文件提前结束。
- feof()函数读取文件和EOF结束符标志问题
- fread()、fgets()、fgetc()、file_get_contents() 与 file() 函数用于从文件中读取内容。
- fwrite和fread函数的用法小结(怎么样以二进制形式保存和读取文件)
- fwrite和fread函数的用法小结(怎么样以二进制形式保存和读取文件)
- fread读文件读取不全解决方法
- fread读取文件读不全的问题解决
- 高效地读取&解析文件(fread)
- Context []startup failed due to previous errors有效解决方式
- 201503-1
- SDWebImage源码解读之干货大总结
- ccf试题 中间数
- LEETCODE--Island Perimeter
- fread函数读取文件提前结束
- WordPress Transients API – Practical examples
- go语言快速入门:词法基础(3)
- CSS选择器
- 2.5.3 HTML5布局的使用
- SHOW SLAVE STATUS 详解
- 夺冠概率 蓝桥杯
- BZOJ 2561(最小生成树-最小割)
- 个人感悟