版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Lesson 17 Data Files 2,Hu Junfeng 2007/12/05,2,The Arrangements:,Dynamic Data Structures C+ introduction (part1) C+ introduction (part2) Database introduction (?) Review January 7, the happy ending.,3,Todays objectives,Advanced string operations Random File Access Passing and Returning File Pointers
2、 Binary Files Dynamic Memory Allocation Linked List Basic,4,Reading from Text Files EOF,C appends the low-value hexadecimal byte 0 x00 as the end-of-file (EOF) sentinel when the file is closed EOF sentinel is never counted as part of the file,5,Reading from a Text File (exp.),6,Reading from and Writ
3、ing to Text Files(cont.),Prototypes in stdio.h Examples Examples fgetc(inFile); fgets(message,10,inFile); fscanf(inFile,%lf, fgetc() and fscanf() return EOF when the end-of-file marker is detected fgets() returns a NULL instead,7,Standard Device Files,stdin data stream (read) from keyboard stdout da
4、ta stream (write) from monitor stderr data stream (write) for error message,8,Can be replaced by getchar();,9,Get a line from stream,There are two line-oriented I/O functions, i.e. fgets() and fputs(), which allow us read and write lines instead of chracters. The function prototypes are:char *fgets(
5、char *s, int n, FILE *stream) ;int *fputs(const char *s, FILE *stream);The second argument, n, of fgets() specifies the size of the array in which the string is stored.,10,Prog11.4,11,char * strstr(char *s1, const char *s2);,strstr returns a pointer to the beginning of the sub-string or NULL if not
6、found. Exp: char string1 = “paper tiger; char string2=“tiger; void *pointer; pointer = strstr(string1, string2); ,12,13,char *strtok( char *str1, const char *str2 );,The strtok() function returns a pointer to the next token in str1, where str2 contains the delimiters that determine the token. strtok
7、() returns NULL if no token is found. In order to convert a string to tokens, the first call to strtok() should have str1 point to the string to be tokenized. All calls after this should have str1 be NULL.,14,char *strtok( char *str1, const char *str2 );,15,16,Text to HTML ,17,18,ASP and B/S Archite
8、cture,request,Active server pages,respond,19,Random File Access,fseek(fileName, offset, origin),file stream,File* fp;,program,20,Random File Access,rewind() resets the current position to the start of the file rewind(inFile) fseek() allows the programmer to move to any position in the file fseek(fil
9、eName, offset, origin) Origin: SEEK_SET, SEEK_CUR, and SEEK_END ftell() returns the offset value of the next character that will be read or written ftell(inFile);,21,Random File Access (continued),Examples of fseek() are fseek(inFile,4L,SEEK_SET); fseek(inFile,4L,SEEK_CUR); fseek(inFile,-4L,SEEK_CUR
10、); fseek(inFile,0L,SEEK_SET); fseek(inFile,0L,SEEK_END); fseek(inFile,-10L,SEEK_END);,22,Random File Access (exp),23,Passing and returning file pointer,#include #include FILE *getOpen(); /* function prototype */ void inOut(FILE *); /* function prototype */ int main() FILE *outFile; outFile = getOpen
11、(); inOut(outFile); fclose(outFile); return 0; ,FILE *getOpen() FILE *fpointer; char name13; printf(nEnter a file name: ); gets(name); fpointer = fopen(name,w); if(fname = NULL) printf(nFailed to open the file %s.n, name); exit(1); return(fpointer); ,24,第三次附加作业(可选) 唐诗鉴赏网站的自动生成,要求: 实现方便的诗歌浏览功能。 设计(部分实现)诗歌浏览页面的相关链接
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年酒水供货合同范文(二篇)
- 2024年企业租赁经营合同简易版(3篇)
- 2024年标准的个人借款合同范文(二篇)
- 2024年加盟店合同格式版(2篇)
- 2024年企业工资集体协议电子版(二篇)
- 2024年混凝土劳务分包合同范本(二篇)
- 2024年私人借款合同格式范文(二篇)
- 人教版四年级上册数学期末测试卷及答案(考点梳理)
- 六年级下册道德与法治第三单元《多样文明 多彩生活》测试卷带答案(培优)
- 部编版三年级下册道德与法治第三单元《我们的公共生活》测试卷及完整答案(历年真题)
- JTG 3432-2024 公路工程集料试验规程
- 新能源汽车驱动电机及控制系统检修 课件 3.1驱动电机的就车拆装
- 养老院安全隐患检查与整改方案
- 河南郑州暴雨案例分析报告
- 种植牙围手术期护理
- 低压电工基础知识培训总结
- 上海市2021年中考数学真题卷(含答案与解析)
- 新型抗病毒药物对日本脑炎的治疗潜力
- 2023年设备生产主管年终安全工作总结
- GB/T 43576-2023口腔清洁护理用品牙膏对去除外源性色斑效果的实验室测试方法
- 银行手语培训.ppt
评论
0/150
提交评论