C语言read()函数:用于读取打开文件的内容 您所在的位置:网站首页 c语言中怎么从文件中读取文件内容 C语言read()函数:用于读取打开文件的内容

C语言read()函数:用于读取打开文件的内容

2023-04-06 02:35| 来源: 网络整理| 查看: 265

函数名:read

头文件:

函数原型: int read(int handle,void *buf,int len);

功能:用于读取打开文件的内容

参数:int handle 为要读取的文件

          void *buf  为要将读取的内容保存的缓冲区

          int len    读取文件的长度

返回值:返回实际读取的字节数

程序例:创建文件,内容为 I like www.dotcpp.com very much!

//打开文件,读取文件的内容 #include #include #include int main(void){    int fd=open("D:\\a.txt",O_RDONLY);    if(fd==-1){       printf("can not open the file\n");       return 1;    }    char buf[1024]={"\0"};    int len=read(fd,buf,1024);    printf("%s\nlen=%d\n",buf,len);    close(fd);    return 0; }

 

运行结果

I like www.dotcpp.com very much! len=32



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有