C语言实现文件分割

 时间:2024-10-11 00:29:50

该程序实现将一个大文件分割成小文件功能

方法/步骤

1、首先打开VC++6.0

C语言实现文件分割

2、选择文件,新建

C语言实现文件分割

3、选择C++sourcefile新建一个空白文档

C语言实现文件分割

4、先声明头文件#include<stdio.h>#include<stdlib.h>#include<string.h>

C语言实现文件分割

5、文件内容转移函数,功能是:将sfp所指向的文件中衡痕贤伎size字节的数据转移到dfp所指向的文件中去voidFilePartition(FI讣嘬铮篌LE*sfp,FILE*dfp,intsize){ints=size;charch;while(s!=0){ch=fgetc(sfp);if(ch==EOF)break;fputc(ch,dfp);s--;}fclose(dfp);}

C语言实现文件分割

6、主函数intmain(拘七呷憎){/*用户输入的要分割的文件名*/charsfilename[20];/*用户输入分割后要保存到的文件名*/chardfilename[20];惺绅寨瞀/*定义要分割的字节数*/charch;intsize;FILE*sfp,*dfp;printf("Pleaseinputfilenametobepartitioned:\n");/*得到要分割的文件名*/gets(sfilename);/*以只读方式打开要分割的文件*/if((sfp=fopen(sfilename,"rb"))==0){printf("Can'topenthefile:%s\n",sfilename);exit(0);}while(!feof(sfp)){/*取得下一个要文件名*/printf("inputfilenametosavethepartitionedfile:\n");scanf("%s",dfilename);if((dfp=fopen(dfilename,"wb"))==0){printf("Can'topenorcreatethefile:%s\n",dfilename);exit(0);}/*读入此次分割的字节数*/printf("Pleaseinputthesizeofpartition:\n");scanf("%d",&size);/*依次读入指定字节数的文件内容,并存入到相应文件中*/FilePartition(sfp,dfp,size);}printf("Partitionthefile%ssuccessfully!",sfilename);getch();return0;}

C语言实现文件分割

7、运行结果

C语言实现文件分割

css怎么调整背景图片的位置? Dw CC 2018怎么文件类型改为javascript vs2015中文旗舰版怎么布局表格页面 VS如何安装easyx图形库 css如何设置span的宽度和高度
热门搜索
少女音 王者天下漫画 疑问图片 狼少女辛希雅 花岗岩图片