- 4
- 0
- 约1.67万字
- 约 28页
- 2018-12-02 发布于浙江
- 举报
冯毅《程序设计基础》c014-c10
* 文本文件特点:行结束标志由一个回车符和一个换行符组成 读文件时:将回车和换行合并成一个换行 写文件时:将换行符展开成回车和换行两个符号 suitable for character operation * Old C version,there are two kinds of management method. 1. Buffer file high-level I/O ,ASCII file 2.non-buffer file low-level I/O,binary file ANSI C,there is only buffer file 特点:减少读写次数,提高速度和数据管理质量 * a data structure in the C program which represents the file Details of the struct are private to the standard C I/O library routines C program can operate directly on variables (data in main memory), so… Need to make a connection between the data on the disk and variables in main memory * r+ :以读、写方式打开一个已经存在的文件,文件指针指向其首部 w+ :建立一个新文件以读、写,文件指针指向其首部 a+ :以读、写方式打开一个已经存在的文件,文件指针指向其尾部 a/a+:向文本/二进制文件尾追加数据,若文件不存在,建立 System defines three file pointers automatically. stdin , stdout , stderr. They are constants, however,not variables,so it is not possible to assign to them. Opening a file: making a connection between the operating system (file name) and the C program (file variable) Files stdin/stdout (used by scanf/printf) are automatically opened connected to the keyboard and display * 因为fclose先把缓冲区数据输出 到磁盘文件,然后才释放文件指针 After having used the file ,it must be closed. int fclose(FILE *stream) fclose flushes any unwritten data for stream, discards any unread buffered input, frees any automatically allocated buffer, then closes the stream. * 1.若文件在当前目录下: fp=fopen(aa.txt,r); 2.若文件不在当前目录下: fp=fopen(d:\\fengyi\\bkc\\aa.txt,r); 2.若从键盘输入带路径文件名: char infile[30]; scanf(%s,infile); fp=fopen(infile,r); 必须输入:d:\fengyi\bkc\aa.txt * 第一个参数可以是:字符串常量、char数组名、char指针 * 说明:输入时,要将ASCII码转换成二进制;输出时,要将二进制转换成ASCII码 //将i和t按%d,%6.2f格式输出到fp文件 //若文件中有3,4.5 ,则将3送入i, 4.5送入t When we input the datum,convert ASCII to binary. When we output datum,convert binary to ASCII. Spend much time,seldom to use them End of File (EOF) Status EOF: a special status value Returned by scanf and fscanf when end of data is reached defined in stdio.h #define EOF (some negative v
您可能关注的文档
最近下载
- 2025年山东力明科技职业学院单招语文测试试卷大全.docx VIP
- 高考物理机械能常用模型最新模拟题精练专题31机械能+弹簧连接体+计算题(原卷版+解析).docx VIP
- 2025年湖南铁路科技职业技术学院单招职业技能考试题库及参考答案1套.docx
- 高考物理真题5年分类汇编专题10磁场(全国通用)(含解析).docx VIP
- 2025年成都七中自主招生物理试题 .pdf VIP
- 2025年城市管理协管员招聘考试(城市管理执法)历年参考题库含答案详解.docx VIP
- 保安服务方案 投标方案(技术标).doc
- 2024-2025学年人教版九年级上册化学期末专项训练:计算题(含解析).pdf VIP
- 【泰国投资促进委员会(BOI)】2025年投资促进项目申请指南.docx
- 陕西省09计价规则.pdf VIP
原创力文档

文档评论(0)