求c io高手解答

hacqing 2012-06-04 11:52:05
今天回来遇到一问题,



//1.txt文件大小为1444byte
//windows :
#include <io.h>

//linux #include <unistd.h>

#include <fcntl.h>
/*#include <stdio.h>*/

int main(void)
{
// FILE * file = fopen("f:/temp/1.txt", "rb");
int fd = 0;
char buff[1024];
int reads = 0;
int counts = 0;
// fd = file->_file;
fd = _open("f:/temp/1.txt", O_RDONLY, 0777);

while ((reads = _read(fd, buff, sizeof(buff))) > 0) {
counts += reads;
}

reads += 0;
return 0;
}
//xp3下vs2008,counts 为1408, ubuntu 12.04下gcc,counts为1444





// #include <io.h>
// #include <fcntl.h>
#include <stdio.h>

int main(void)
{
FILE * file = fopen("f:/temp/1.txt", "rb");
int fd = 0;
char buff[1024];
int reads = 0;
int counts = 0;
fd = file->_file;
// fd = _open("f:/temp/1.txt", O_RDONLY, 0777);

while ((reads = _read(fd, buff, sizeof(buff))) > 0) {
counts += reads;
}

reads += 0;
return 0;
}
//xp3下vs2008,counts 为1444


真心伤不起,以前只是听说window对c标准支持不够,这回不知道是不是这个问题,请各位各抒己见,谢谢。
很久不灌水,分不多。全部家当,哈哈。
...全文
106 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hacqing 2012-06-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
跟你打开文件的模式有关的吧。第二个例子中是按照binary打开的,第一个没有写明,默认应该是text。
你第一个例子中打开文件是加上_O_BINARY说不定结果会不一样。
[/Quote]
谢1楼。结贴
guzl86 2012-06-05
  • 打赏
  • 举报
回复
不知道,求解。。。。。。
proorck6 2012-06-05
  • 打赏
  • 举报
回复
fopen函数的使用问题,应该就是打开文件的模式不对。
cryingbee 2012-06-05
  • 打赏
  • 举报
回复
跟你打开文件的模式有关的吧。第二个例子中是按照binary打开的,第一个没有写明,默认应该是text。
你第一个例子中打开文件是加上_O_BINARY说不定结果会不一样。

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧