C语言程序设计课件PPT英文Cprogramla.ppt
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《C语言程序设计课件PPT英文Cprogramla.ppt》由用户(三亚风情)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 课件 PPT 英文 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
3、 File 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) Buff
4、ered I/O (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:B
5、inary fileASCII 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
6、automatically to guarantee 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 )ope
7、rate file using functionsclose file (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, su
8、ch as the location of a buffer , the 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 st
9、udent .Chapter Seven 2 The function of opening 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 fop
10、en ( ) readwriteappendOpen/close fileChapter SevenOpen/close 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
11、a file pointer.Chapter Seven If process is successful , the returned value 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 strea
12、mbBinary stream+Permit read/write If fopen fails , return value is zero ( NULL pointer) when: 1)fopen wants 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 &
13、 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 file 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 st
14、ring of up to n-1 characters from stream and places them into stringfputs(string, stream) 1 read/write file functionsfgetc (fp), fputc(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 (-
15、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 argc, 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
16、) 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); fclose (fpd);Input three strings( file name)Source file name object file name The function of
展开阅读全文