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