您的位置:首页 > 运维架构

fopen 与 open可以转换 即 FILE-->FD

2012-05-29 11:18 302 查看
#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);也行

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: