c语言小型文件管理系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

/*小型文件管理系统,实现文本文件的显示,文件的复制、删除、重命名和两个文件的连接和比较功能*/#includestdio.h#includestdlib.h#includestring.hvoiddisplay(){charfilename[20];FILE*fp;printf(Pleaseinputafilename:);scanf(%s,filename);if((fp=fopen(filename,r))==NULL){printf(Cannotopenthisfile!!!);exit(0);}while(!feof(fp)){putchar(fgetc(fp));}printf(\n);fclose(fp);}voidcopy(){FILE*in,*out;charinfile[20],outfile[20];printf(Pleaseinputtheinfilename:);scanf(%s,infile);printf(Pleaseinputtheoutfilename:);scanf(%s,outfile);if((in=fopen(infile,r))==NULL){printf(Cannotopenthisfile!!!);exit(1);}if((out=fopen(outfile,w))==NULL){printf(Cannotopenthisfile!!!);exit(2);}while(!feof(in)){fputc(fgetc(in),out);}printf(\n);fclose(in);fclose(out);}voidconnect(){FILE*fp1,*fp2;charfilename1[20],filename2[20];printf(Pleaseinputthefilename1:);scanf(%s,filename1);printf(Pleaseinputthefilename2:);scanf(%s,filename2);if((fp1=fopen(filename1,r))==NULL){printf(Cannotopenthisfile!!!);exit(0);}if((fp2=fopen(filename2,a+))==NULL){printf(Cannotopenthisfile!!!);exit(1);}while(!feof(fp1)){fputc(fgetc(fp1),fp2);}fclose(fp1);fclose(fp2);}voidcompare(){inti;charch1,ch2;FILE*fp1,*fp2;charfilename1[20],filename2[20];printf(Pleaseinputthefilename1:);scanf(%s,filename1);printf(Pleaseinputthefilename2:);scanf(%s,filename2);if((fp1=fopen(filename1,r))==NULL){printf(Cannotopenthisfile!!!);exit(0);}if((fp2=fopen(filename2,r))==NULL){printf(Cannotopenthisfile!!!);exit(1);}while(!feof(fp1)&&!feof(fp2)){ch1=fgetc(fp1);ch2=fgetc(fp2);if(ch1==ch2){i=1;}else{i=0;}}if(i){printf(%sand%sarethesame!!!\n,filename1,filename2);}else{printf(%sand%saredifferent!!!\n,filename1,filename2);}fclose(fp1);fclose(fp2);}voidcounter(){intj=0;FILE*fp;charfilename[20];printf(Pleaseinputfilename:);scanf(%s,filename);if((fp=fopen(filename,r))==NULL){printf(Cannotopenthisfile!!!);exit(0);}while(!feof(fp)){fgetc(fp);j++;}printf(Thisfilelengthis%d\n,j-1);fclose(fp);}main(){charoldname[20],newname[20],filename[20];intj=1,choice;printf(*********************MENU*********************\n);printf(0.DisplayTextFile\n);printf(1.CopyFile\n);printf(2.ConnectFile\n);printf(3.CompareFile\n);printf(4.DeleteFile\n);printf(5.CountertheLengthofFile\n);printf(6.RenameFile\n);printf(7.Quit\n);printf(**********************************************\n);while(j){printf(Pleaseenteryourchoice0~7:);scanf(%d,&choice);switch(choice){case0:display();break;case1:copy();break;case2:connect();break;case3:compare();break;case4:printf(Pleaseinputthefilenameyouwanttodelete:);scanf(%s,filename);if(remove(filename)==0){printf(Removed\n);}else{perror(remove);}break;case5:counter();break;case6:printf(Pleaseinputoldname:);scanf(%s,oldname);printf(Pleaseinputnewname:);scanf(%s,newname);if(rename(oldname,newname)==0){printf(Renamed%sto%s.\n,oldname,newname);}else{perror(rename);}break;case7:j=0;break;}}}

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功