C语言程序设计课件英文Cprogramla.ppt
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《C语言程序设计课件英文Cprogramla.ppt》由用户(ziliao2023)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 课件 英文 Cprogramla
- 资源描述:
-
1、LOGOChapter Seven FileFileChapter SevenContents Introduction1Open/close file2Read/write file 3 Check the state of the opening file4The location of the file pointer54Chapter SevenHow to get the data while run a program?Where will the result in?How can input the result of a program to another program?
2、Introduction The procedure of C language EditLinkCompile Chapter Seven Introductionprogram format outputcharacter outputstring outputinitializationassignment input from keyboardmemorymemoryformat inputcharacter inputstring input Read data from a file Write data to a fileChapter Seven Introduction Fi
3、le is the gather of related information saved in memory device(assistant memory)OS manages system in files Processing files means file input/out processing.Procedure 1 open file2 file read/write 3 close file.Interface input/out devices are treated as files in C.File accessing methods:1)Buffered I/O(
4、or stream I/O)2)Unbuffered I/O(or low-level I/O)Chapter Seven IntroductionBuffered (temporary storage location)Well discuss Buffered I/O in our lecture In buffered I/O,-open a communication area in RAMDISkPROGRAMOutput file buffer Input file bufferThere are two ways to deal with file:Binary fileASCI
5、I file Chapter Seven Introduction Stream is the abstract of file used to deal with file.There are two kinds of streams in C.The character is ASCII code.one ASCII code occupies one byte,new line n is end of line.After read/write a character from/to ASCII file,the fp increases automatically to guarant
6、ee the read/write sequences.Text streamBinary streamStoring data to disk in the form the same as in RAM.Example:10000 In binary file,use 2 bytes In ASCII file,use 5 bytesChapter SevenOpen/close fileHow to magange a file in C?PointerOperations open file(load file)operate file using functionsclose fil
7、e (remove file from memory)A file system creat a new filedelete an old oneread/write access a file by its namemanage the memory file usedlimit the users rightChapter SevenOpen/close file File pointer,points to a structure that contains information about the file,such as the location of a buffer,the
8、current character position in the buffer,whether the file is being read or written,and whether errors or end of file have occurred.Users dont need to know the details,because the definitions obtained from include a structure declaration called FILE.I am a student.Chapter Seven 2 The function of open
9、ing a file:FILE*fp;uppercase letters,otherwise,cant be recognized,defined to standard structure,key-word#include is necessary fopen(filename,*mode);stringchar arraychar pointer paths are allowed 1 files pointer:opening a file use function fopen()readwriteappendOpen/close fileChapter SevenOpen/close
10、filefp=fopen(“file.txt”,“r”);open file.txt,read in ASCIIOpening a file means.returns a file pointerspecify the operation to be done points to the first location of file buffer.r-readfile.txtwhich The returned value is assigned to a file pointer.Chapter Seven If process is successful,the returned val
11、ue is a file pointer.(address)FLIE *fp;Otherwise,return NULL pointer.if(fp=fopen(“file.txt”“r”)=NULL)printf(“cant open file n”);exist(1);Open/close fileSymbolExplanationrreadwwriteaappendtText streambBinary stream+Permit read/write If fopen fails,return value is zero(NULL pointer)when:1)fopen wants
12、to open a non existed file for reading.2)read a file not permitted read.3)create a file but disk is full.4)disk sector is bad.Chapter Seven3 Close a fileClose a file opened,argument&a pointer to file to be closed in order to 1)release fp and 2)clean up the buffer.fclose(fp);Open/close file Opened fi
13、le must be closed before ending a program,otherwise,data may be lost.Chapter Seven Writes string into file pointed by stream File read/writefgets(string,n,stream)Reads a string of up to n-1 characters from stream and places them into stringfputs(string,stream)1 read/write file functionsfgetc(fp),fpu
14、tc(fp)read/write a char from/to file read:c=fgetc(fp);read a char from named file.write:fputc(c,fp);write c to named file.Prototype in stdio.h return EOF(-1)if a)at the end of file;b)detecting an error;Using function fgets()and fputs()can realize string input/ouput in files.Chapter Seven main(int ar
15、gc,char*argv )int c;FILE *fpr,*fpd;if(argc!=3)putchar(007);puts(Usage:copy file1,file 2);exit();if(fpr=fopen(argv1,r)=NULL)printf(%c,007);printf(file%s cant open n,argv 1);exit();if(fpd=fopen(argv2,w)=NULL)printf(files%s cant openn ,argv2);exit();while(c=fgetc(fpr)!=EOF)fputc(c,fpd);fclose(fpr);fclo
展开阅读全文