使用fopen()函数以不同模式打开磁盘文件(里面有个bug)
2015-10-19 00:00
411 查看
// openfiles.c -- 演示fopen()函数 #include <stdio.h> #include <stdlib.h> int main(void){ FILE *fp; char ch, filename[40], mode[4]; while(1){ /*输入文件名和模式*/ puts("\nEnter a filename: "); gets(filename); puts("\nEnter a mode (max 3 characters): "); gets(mode); /*尝试打开文件*/ if((fp = fopen(filename, mode)) != NULL){ printf("\nSuccessful opening %s in mode %s.\n", filename,mode); fclose(fp); puts("Enter x to exit, any other to continue."); if((ch = getc(stdin)) == 'x') break; else continue; } else { fprintf(stderr, "\nError opening file %s in mode %s.\n", filename, mode); puts("Enter x to exit, any other to try again."); if((ch = getc(stdin)) == 'x') break; else continue; } } return 0; }
相关文章推荐
- opkg安装到U盘
- ipk 编译 包不存在解决 openwrt下使用lame
- linux下删除文件
- RT5350 OpenWrt下 I2C 问题
- linux下printf缓存输出问题
- openwrt下检测U盘是否插入
- Android系统架构、JVM和DalvikVM的区别
- Hadoop集群管理 fsimage和edits工作机制内幕
- Sqoop2 安装配置
- 运维人,你应该了解的三张武功心法图
- Linux如何查找软件的安装路径
- Linux下*.tar.gz文件解压缩命令
- The APR based Apache Tomcat Native library which a
- 启动tomcat后无法访问
- 关于如何绕过zhihu网站垃圾的禁止复制页面内容的方法(未经测试验证)
- vmvare-centos7-vim
- Apache站点默认首页设置
- Your operating system's lex is insufficient to compile libpcap
- Linux下添加新硬盘,分区及挂载
- keepalived构建高可用集群