read()

王朝百科·作者佚名  2010-01-04
窄屏简体版  字體: |||超大  

函数名: 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 <sysstat.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;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航