Dotcpp  >  编程教程  >  io.h头文件  >  C语言fdopen()函数:将流与文件句柄连接

C语言fdopen()函数:将流与文件句柄连接

点击打开在线编译器,边学边练

函数名:fdopen

头文件:<io.h>

函数原型: int fdopen(int handle,char* type);

功能:将流与文件句柄连接

参数: int handle  为要操作的文件句柄 ,char *type  指定流打开方式

返回值: 返回指向该流的文件指针


程序例:使用函数连接文件句柄和流,以流的方式向文件中输入一行字符串

#include<stdio.h>

#include<io.h>

#include<fcntl.h>

int main(void){

   int fd=open("D:\\a.txt",_O_RDWR+O_CREAT);

   if(fd==-1){

      printf("can not reate the file\n");

      return 1;

   }

   FILE *fp=fdopen(fd,"w");

   fprintf(fp,"mingri soft\nminri book\n");

   fclose(fp);

   printf("OK");

   return 0;

}

 

运行结果

OK



本文固定URL:https://www.dotcpp.com/course/457

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)