请输入您要查询的百科知识:

 

词条 read()
释义

§ 名称

函数名: read

功 能: 从文件中读

用 法: int read(int handle, void *buf, int nbyte);

§ 程序例

#include <stdio.h>

#include <io.h>

#include <alloc.h>

#include <fcntl.h>

#include <process.h>

#include <sys\\stat.h>

int main(void)

{

void *buf;

int handle, bytes;

buf = malloc(10);

/*

Looks for a file in the current directory named TEST.$$$ and attempts

to read 10 bytes from it. To use this example you should create the

file TEST.$$$

*/

if ((handle =

open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1)

{

printf("Error Opening File\");

exit(1);

}

if ((bytes = read(handle, buf, 10)) == -1) {

printf("Read Failed.\");

exit(1);

}

else {

printf("Read: %d bytes read.\", bytes);

}

return 0;

}

随便看

 

百科全书收录594082条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/9/21 20:37:28