Function name : read
Header file : <io.h>
Function prototype : int read(int handle,void *buf,int len);
Function : Used to read the contents of an open file
Parameter : int handle is the file to be read
void *buf is the buffer to save the read content
int len reads the length of the file
Return value : Returns the actual number of bytes read
Program example : Create a file with the content I like www.dotcpp.com very much!
//Open the file and read the contents of the file #include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){intfd=open(D:\a.txt,O_RDONLY) ;if(fd==-1){print f(cannotopenthefilen);return1;}charbuf[1024]={ };intlen=read(fd,buf,1024);printf(%snlen=%dn,buf,len);close( fd);return0;}
Running results
Ilikewww.dotcpp.comverymuch!len=32