Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C以字节块形式读取文件_C_Unix - Fatal编程技术网

C以字节块形式读取文件

C以字节块形式读取文件,c,unix,C,Unix,找不到关于此的适当文档,但我正在尝试使用*nix系统调用read读取文件。我要读取1024字节块的文件。我不确定以下内容是否正确: while (read(fd, buffer+i, 1024) == 1){ i++; } 有人能验证一下吗?如果你不能使用man,为什么不直接搜索 反正你用错了。如果你想分块阅读,你应该这样做 // consider that we allocated enough memory for buffer // and buffer is b

找不到关于此的适当文档,但我正在尝试使用*nix系统调用read读取文件。我要读取1024字节块的文件。我不确定以下内容是否正确:

while (read(fd, buffer+i, 1024) == 1){
            i++;
}
有人能验证一下吗?

如果你不能使用man,为什么不直接搜索

反正你用错了。如果你想分块阅读,你应该这样做

// consider that we allocated enough memory for buffer
// and buffer is byte array
ssize_t r = 0, i = 0;
do {
  r = read( fd, buffer + i, 1024 ); // try to read 1024 bytes
  i += r; 
} while( r > 0 ); 

“你不为你工作吗?”约翰3136我的人离开了我。