700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > linux c fopen open 互相转换 文件指针 到 文件描述符 FILE* 转 FD

linux c fopen open 互相转换 文件指针 到 文件描述符 FILE* 转 FD

时间:2023-01-16 06:26:03

相关推荐

linux c fopen open 互相转换 文件指针 到 文件描述符 FILE* 转 FD

FILE*--fileno()--->fd;

实例如下:

#include <stdio.h>int main(){FILE *fp = NULL;int i = 0;fp = fopen("test.txt", "w+");fclose(fp);while(i++<1500){fp = fopen("test.txt", "a"); // "注意W+对int fd = fileno(fp);的影响"if (fp == NULL)return 0;fprintf(fp, "hello%d\n",i);fflush(fp);int fd = fileno(fp); //如果是W+这里文件被清空的影响write(fd, "world\n", sizeof("world\n"));fclose(fp); // close(fd);也行}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。