linux c之fdopen(int fd, const char *type)使用总结
生活随笔
收集整理的這篇文章主要介紹了
linux c之fdopen(int fd, const char *type)使用总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、fdopen(int fd, const char *type)的介紹
比如一寫特殊文件不能用io打開,我們先要用open函數得到文件描述符,也就是這個fdopen函數的第一個參數,第二個參數是常量,不同類型不同意義,如下圖
2、代碼演示
#include<stdio.h> #include<fcntl.h>int main(void) {FILE *fp;int fd;if ((fp = fopen("hello.txt", "w+")) == NULL) {printf("fopen file error\n");return 0;}fprintf(fp, "hello word\n");fclose(fp);if ((fd = open("hello.txt", O_RDWR)) == -1) {printf("open file fail\n");return 0;}if ((fp = fdopen(fd, "a+")) == NULL) {printf("
總結
以上是生活随笔為你收集整理的linux c之fdopen(int fd, const char *type)使用总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux之文件类型
- 下一篇: linux c之用fputc和fgetc