%10s中的10是什么c语言,c语言10解读.ppt

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值