C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc

C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc

ID:50299724

大小:44.50 KB

页数:6页

时间:2020-03-07

C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc_第1页
C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc_第2页
C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc_第3页
C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc_第4页
C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc_第5页
资源描述:

《C语言程序设计 教学课件 作者 罗朝盛第9章 习题参考答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、《C语言程序设计》习题参考答案第9章习题参考答案1.填空题(1)文本文件/二进制文件(2)创建a文件(3)打开a文件,并且文件读写位置指针在文件尾(4)将字符变量ch中的字符写入fp所指向的文件/从fp所指向的文件中读取n-1个字符,并且写入数组s中(5)0(6)for(i=0;i<30;i++)fread(&stud[i],sizeof(structstudent_type),1,fp)(7)fseek(fp,30L,SEEK_SET)(8)-12.选择题12345678ABCDCCDC3.程序阅读题1-

2、5,-4,-3,-2,total=-142Language!3123456789104.程序填空题1(fp=fopen("c:\data.txt","w"))(ch=getchar())fputc(ch,fp)2stu[i].name,stu[i].sno,stu[i].age,stu[i].address"w"&stu[i],sizeof(structstudent),1,fp《C语言程序设计》习题参考答案3rw5.编程题(1)#includevoidmain(){FILE*fp1,*

3、fp2;charch;if((fp1=fopen("C:\Mydir\String.txt","r"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}if((fp2=fopen("C:\Mydir\NewString.txt","w"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}while((ch=fgetc(fp1))!=EOF){if(ch>='A'

4、&&ch<='Z')ch+=32;elseif(ch>='a'&&ch<='z')ch-=32;fputc(ch,fp2);};fclose(fp1);fclose(fp2);remove("C:\Mydir\String.txt");rename("C:\Mydir\String.txt","C:\Mydir\NewString.txt");}(2)#includeintsearch(FILE*fp,charch);voidmain(){FILE*fp;charfilenam

5、e[30];charch;intcount;《C语言程序设计》习题参考答案printf("Pleseinputfilename:");gets(filename);printf("Pleseinputthecharacteryouwanttosearch:");scanf("%c",&ch);if((fp=fopen(filename,"r"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}count=search(fp,ch)

6、;fclose(fp);printf("%dtimes!",count);}intsearch(FILE*fp,charch){intnum=0;charx;while((x=fgetc(fp))!=EOF)if(x==ch)num++;returnnum;}(3)#includevoidmain(){FILE*fp1,*fp2;intx,temp;printf("Pleaseinputthenumber:");scanf("%d",&x);if((fp1=fopen("C:\M

7、ydir\source.dat","r"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}if((fp2=fopen("C:\Mydir\destination.dat","w"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}while(!feof(fp1))《C语言程序设计》习题参考答案{fscanf(fp1,"%d",&temp);if(temp%x==

8、0)fprintf(fp2,"%d",temp);};fclose(fp1);fclose(fp2);}(4)#include#defineSTUNUM5/*代表学生人数*/structstudent{charname[20];intChinese;intComputer;intMath;}stu1[STUNUM],stu2[STUNUM];voidmain(){FILE*fp1,*fp2;in

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。