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);也行
}
}
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);也行
}
}
相关文章推荐
- VC 6.0 采用菜单 File—>Open 打开 .dsw 工程时,VC 6.0 界面程序处于僵死状态问题解决
- CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
- git am failed:cannot open <dir>/*.patch: No such file
- 利用OpenOffice.org和Swftools进行实现—doc-->pdf-->swf--格式的转换
- 文件指针和文件描述符之间的相互转换 fd---->fp 和 fp---->fd
- fopen与open可以转换吗
- VC 中 file->open 打不开文件问题解决方法
- 转:fopen与open可以转换吗
- snort在使用过程中遇到的问题:ERROR: OpenAlertFile() => fopen() alert file log/alert.ids:No such file or directory
- VC6.0启动File->open和Project->add file to project崩溃的解决方法
- fwrite fopen > 2GB file
- 在VC6.0用file->open后,出现“MSDEV.EXE-应用程序错误
- file(),file_get_contents(),fopen()->fread()->fclose(),fgets(),fgetc()
- VC6.0file->open出错解决办法
- 【Java.IO】I/O 字节 <-> 字符转换流 —— InputStreamReader,OutputStreamWriter(FileReader,FileWriter)
- 【解决方案】VC++—>add files to folder失效,open-file弹出msdev.exe应用程序错误
- SAP ABAP编程 选择文件对话框 CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
- 1>LINK : fatal error LNK1181: cannot open input file 'xxx.obj'
- XLS文件读取 & cl_gui_frontend_services=>file_open_dialog
- Hard limits for "maximum open file descriptors"