linux c之fdopen(int fd, const char *type)使用总结
来源:互联网 发布:知敬畏守底线强党性 编辑:程序博客网 时间:2024/06/18 07:07
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("fdopen open\n"); return 0; } fprintf(fp, "linux c program"); fclose(fp); return 0;}
3、结果展示
0 0
- linux c之fdopen(int fd, const char *type)使用总结
- NSValue的使用...@encode(type)...int strcmp(const char *, const char *); 返回 0 表示相等
- char * strchr (const char *str, int c);
- c语言库函数【string.h】之strncpy_(char* dst,const char* src,int count)
- C语言库函数之 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
- strrchr(const char * s,int c)
- c语言库函数【string.h】之 substr_(char *dest, const char* src, unsigned int start, unsigned int len)
- C和指针之字符串编程练习8实现char *my_strnchr(char const *str, int ch, int which)
- int const * 、const int *、int *const、const char **与char **
- int atoi(const char*)
- char*const*(*next)(int)
- linux c之main(int argc, char *argv[], char *envp[])参数意义
- C/C++ | 25-15 实现strcmp,int StrCmp(const char *str1, const char *str2)
- Linux int lstat(const char *path, struct stat *buf);
- linux c之提示format‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat
- C库之pipe和fdopen
- Linux-C: const char*如何赋值
- C++(三)const char * a1和 char const * a2
- assets文件夹中文件名有中文导致gradle build时出错
- ES、PES、PS、TS流
- ActiveMQ使用
- 用vue实现点击按钮,滑出面板(二)完结版
- 网吧升级机房问题集
- linux c之fdopen(int fd, const char *type)使用总结
- BPM报销流程开发示例
- CentOS 7 firewalld使用简介
- output buffering vs string concatenation / ob vs 拼接字符串
- Hibernate学习笔记 查询简介
- 一些有用的小程序资料
- 【Awesome Power Mode】
- 记录phantomjs学习(二)
- java future