(8.3.1)--7.3ExamplesofFileOperation.ppt

上传人:奉*** 文档编号:83279438 上传时间:2023-03-29 格式:PPT 页数:18 大小:610.36KB
返回 下载 相关 举报
(8.3.1)--7.3ExamplesofFileOperation.ppt_第1页
第1页 / 共18页
(8.3.1)--7.3ExamplesofFileOperation.ppt_第2页
第2页 / 共18页
点击查看更多>>
资源描述

《(8.3.1)--7.3ExamplesofFileOperation.ppt》由会员分享,可在线阅读,更多相关《(8.3.1)--7.3ExamplesofFileOperation.ppt(18页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Examples of File OperationExamples of File Operation#include#include int main(int argc,char*argv)int temp;FILE*fpr;if(argc=1)printf(Parameter missing!n);exit(0);if(fpr=fopen(argv1,r)=NULL)printf(Can not open the source file!n);exit(0);fseek(fpr,0L,0);while(!feof(fpr)temp=fgetc(fpr);putchar(temp);fcl

2、ose(fpr);return 0;fcat.cExample:Implementation of the function of the command cat#include#include int main(int argc,char*argv)int temp;FILE*fpr;if(argc=1)printf(Parameter missing!n);exit(0);if(fpr=fopen(argv1,r)=NULL)printf(Can not open the source file!n);exit(0);fseek(fpr,0L,0);while(!feof(fpr)temp

3、=fgetc(fpr);putchar(temp);fclose(fpr);return 0;fcat.cExample:Implementation of the function of the command cat#include#include int main(int argc,char*argv)int temp;FILE*fpr;if(argc=1)printf(Parameter missing!n);exit(0);if(fpr=fopen(argv1,r)=NULL)printf(Can not open the source file!n);exit(0);fseek(f

4、pr,0L,0);while(!feof(fpr)temp=fgetc(fpr);putchar(temp);fclose(fpr);return 0;fcat.cExample:Implementation of the function of the command cat#include#include int main(int argc,char*argv)int temp;FILE*fpr;if(argc=1)printf(Parameter missing!n);exit(0);if(fpr=fopen(argv1,r)=NULL)printf(Can not open the s

5、ource file!n);exit(0);fseek(fpr,0L,0);while(!feof(fpr)temp=fgetc(fpr);putchar(temp);fclose(fpr);return 0;fcat.cExample:Implementation of the function of the command cat#include#include int main(int argc,char*argv)int temp;FILE*fpr;if(argc=1)printf(Parameter missing!n);exit(0);if(fpr=fopen(argv1,r)=N

6、ULL)printf(Can not open the source file!n);exit(0);fseek(fpr,0L,0);while(!feof(fpr)temp=fgetc(fpr);putchar(temp);fclose(fpr);return 0;fcat.cExample:Implementation of the function of the command cat#include#include int main(int argc,char*argv)int res;if(argc=1)printf(Parameter missing!n);exit(0);res=

7、remove(argv1);if(res=0)printf(deleted!n);exit(0);else if(res=-1)printf(error happend!n);exit(0);return 0;delete.cExample:Implementation of the function of deleting files#include#include int main(int argc,char*argv)int res;if(argc=1)printf(Parameter missing!n);exit(0);res=remove(argv1);if(res=0)print

8、f(deleted!n);exit(0);else if(res=-1)printf(error happend!n);exit(0);return 0;delete.cExample:Implementation of the function of deleting files#include#include int main(int argc,char*argv)int res;if(argc=1)printf(Parameter missing!n);exit(0);res=remove(argv1);if(res=0)printf(deleted!n);exit(0);else if

9、(res=-1)printf(error happend!n);exit(0);return 0;delete.cExample:Implementation of the function of deleting files#include#include int main(int argc,char*argv)int res;if(argc!=3)printf(Parameter error!n);exit(0);res=rename(argv1,argv2);if(res=0)printf(success!n);elseprintf(error!n);return 0;move.cExa

10、mple:Implementation of the function of the command mv#include#include int main(int argc,char*argv)int res;if(argc!=3)printf(Parameter error!n);exit(0);res=rename(argv1,argv2);if(res=0)printf(success!n);elseprintf(error!n);return 0;move.cExample:Implementation of the function of the command mv#includ

11、e#include int main(int argc,char*argv)char c;FILE*fp1,*fp2;if(argc=2)printf(Parameter missing!n);exit(0);if(fp1=fopen(argv1,rb)=NULL)printf(Can not open the source file!n);exit(0);if(fp2=fopen(argv2,a+)=NULL)printf(Can not establish the output file!n);exit(0);fseek(fp1,0L,0);fseek(fp2,0L,0);while(!f

12、eof(fp1)fread(&c,1,1,fp1);fwrite(&c,1,1,fp2);fclose(fp1);fclose(fp2);return 0;copy.cExample:Implementation of the function of the command cp#include#include int main(int argc,char*argv)char c;FILE*fp1,*fp2;if(argc=2)printf(Parameter missing!n);exit(0);if(fp1=fopen(argv1,rb)=NULL)printf(Can not open

13、the source file!n);exit(0);if(fp2=fopen(argv2,a+)=NULL)printf(Can not establish the output file!n);exit(0);fseek(fp1,0L,0);fseek(fp2,0L,0);while(!feof(fp1)fread(&c,1,1,fp1);fwrite(&c,1,1,fp2);fclose(fp1);fclose(fp2);return 0;copy.cExample:Implementation of the function of the command cp#include#incl

14、ude int main(int argc,char*argv)char c;FILE*fp1,*fp2;if(argc=2)printf(Parameter missing!n);exit(0);if(fp1=fopen(argv1,rb)=NULL)printf(Can not open the source file!n);exit(0);if(fp2=fopen(argv2,a+)=NULL)printf(Can not establish the output file!n);exit(0);fseek(fp1,0L,0);fseek(fp2,0L,0);while(!feof(fp

15、1)fread(&c,1,1,fp1);fwrite(&c,1,1,fp2);fclose(fp1);fclose(fp2);return 0;copy.cExample:Implementation of the function of the command cp#include#include int main(int argc,char*argv)char c;FILE*fp1,*fp2;if(argc=2)printf(Parameter missing!n);exit(0);if(fp1=fopen(argv1,rb)=NULL)printf(Can not open the so

16、urce file!n);exit(0);if(fp2=fopen(argv2,a+)=NULL)printf(Can not establish the output file!n);exit(0);fseek(fp1,0L,0);fseek(fp2,0L,0);while(!feof(fp1)fread(&c,1,1,fp1);fwrite(&c,1,1,fp2);fclose(fp1);fclose(fp2);return 0;copy.cExample:Implementation of the function of the command cp#include#include in

17、t main(int argc,char*argv)char c;FILE*fp1,*fp2;if(argc=2)printf(Parameter missing!n);exit(0);if(fp1=fopen(argv1,rb)=NULL)printf(Can not open the source file!n);exit(0);if(fp2=fopen(argv2,a+)=NULL)printf(Can not establish the output file!n);exit(0);fseek(fp1,0L,0);fseek(fp2,0L,0);while(!feof(fp1)frea

18、d(&c,1,1,fp1);fwrite(&c,1,1,fp2);fclose(fp1);fclose(fp2);return 0;copy.cExample:Implementation of the function of the command cp#include#include int main(int argc,char*argv)char c;FILE*fp1,*fp2;if(argc=2)printf(Parameter missing!n);exit(0);if(fp1=fopen(argv1,rb)=NULL)printf(Can not open the source f

19、ile!n);exit(0);if(fp2=fopen(argv2,a+)=NULL)printf(Can not establish the output file!n);exit(0);fseek(fp1,0L,0);fseek(fp2,0L,0);while(!feof(fp1)fread(&c,1,1,fp1);fwrite(&c,1,1,fp2);fclose(fp1);fclose(fp2);return 0;copy.cExample:Implementation of the function of the command cpEmbedded Software DesignEmbedded Software Design

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com