c语言10解读.ppt

  1. 1、本文档共47页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
c语言10解读

Introduction to Computer (C Programming) Chapter 10 File Management in C Roadmap 10.1 Introduction 10.2 File open 10.3 File close 10.4 Input and output 10.5 error process 10.6 random access 10.1 Introduction Until now we have been using the functions such as scanf and printf to read and write data. These are console oriented I/O functions, which always use the terminal (keyboard and screen) as the target place. This works fine as long as the data is small. 10.1.1 Problem Many real-life problems involve large volumes of data, where the console oriented I/O operations pose two major problems: 1. It becomes cumbersome and time consuming to handle large volumes of data through terminals. 2. The entire data is lost when either the program is terminated or the computer is turned off. 10.1.2 Solutions Basic idea Need a more flexible approach where data can be stored on the disk and read whenever necessary, without destroying the data. This method employs the concept of file to store data. 10.1.3文件分类 按数据的组织形式: 文本文件( ASCII文件),每个字节存放一个字符的ASCII码 二进制文件:数据按其在内存中的存储形式原样存放 文本文件与二进制文件的比较 文本文件:便于对字符逐个进行处理,也便于对字符进行输出。但是占用内存较多,需要转换时间。 二进制文件:可以节省存储空间和转换时间,但一个字节并不对应一个字符,不能直接输出。 10.1.4 Using files in C stdio.h. To use a file in a C program, you Declare a variable of type FILE *. Associate the variable with an actual file by calling the fopen function. Call the appropriate functions in stdio.h to perform the necessary I/O operations. Indicate that the file operations are complete by calling fclose. Declare a variable of type FILE *. FILE *fp; 缓冲文件系统 从磁盘读数据 磁盘-缓冲区(等缓冲区满了之后)-程序中的变量 向磁盘写数据 数据-缓冲区(等缓冲区满了之后)-磁盘 10.2 Defining and opening a file 如果要操作一个文件,需要知道文件的相关信息,为其准备相应的缓冲区,缓冲区管理变量等。 在头文件stdio.h 中定义了一个名为FILE的结构体类型 文件打开时,系统自动建立文件结构体(FILE)变量,文件指针就要指向缓冲区的首地址。 程序通过这个指针获得文件信息,访问文件 文件关闭后,它的文件结构体被释放 10.2 Defining and opening a file The general format for declaring and opening a file is as following : FILE *fp; fp = fopen(“filename”, “mode”); The first statement declares the var

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档