如何阻止 Windows C 库将“\r\n”转换为“\r\n”到“\n”当用C读取文本文件时?
我有一个普通的文本文件,其行以普通 \r\n 结尾。然而,当使用'open'和'read'时,Windows将所有\r\n转换为\n。我知道这意味着我必须以二进制模式打开文件,但函数“open”没有提供此选项,它只有只读、只写或读写。
这是代码:
int File_Size = ...;
char* Buffer = (char*)malloc(File_Size);
int Handle = open(File_Path,O_RDONLY);
read(Handle,Buffer,File_Size);
close(Handle);
I have a normal text file that lines end with normal \r\n. However, when using 'open' and 'read', Windows convert all the \r\n to \n. I know this means I have to open the file in binary mode but the function 'open' doesn't give this option, it has only read-only, write-only, or read-write.
This is the code:
int File_Size = ...;
char* Buffer = (char*)malloc(File_Size);
int Handle = open(File_Path,O_RDONLY);
read(Handle,Buffer,File_Size);
close(Handle);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
O_RDONLY|O_BINARY
。Try using
O_RDONLY|O_BINARY
.