帮忙写一个c语言程序,作用是写一个分割文件的程序,原文件太大,无法装的下,需要分割
答案:1 悬赏:80 手机版
解决时间 2021-12-01 01:58
- 提问者网友:那叫心脏的地方装的都是你
- 2021-11-30 06:56
帮忙写一个c语言程序,作用是写一个分割文件的程序,原文件太大,无法装的下,需要分割
最佳答案
- 五星知识达人网友:逐風
- 2021-11-30 07:46
#include
#include
#define TARGET_SIZE (100*1024*1024) //分割为100M一个文件
int main()
{
char name[100];
FILE *in, *out;
char target[100];
int cnt=1,c, n=0;
printf("input source file name and path:");
gets(name);
in = fopen(name, "rb");
if(in == NULL)
{
printf("can not read file
");
return -1;
}
while(!feof(in))
{
sprintf(target, "%s.part%d",name, cnt);
out = fopen(target, "wb");
if(out == NULL)
{
printf("open %d file to write failed
",cnt);
return -1;
}
n = 0;
while((c=fgetc(in)) != EOF && n {
fputc(c, out);
n++;
}
fclose(out);
cnt ++;
}
fclose(in);
printf("done! the file is cut to %d file(s)
", cnt-1);
return 0;
}
#include
#define TARGET_SIZE (100*1024*1024) //分割为100M一个文件
int main()
{
char name[100];
FILE *in, *out;
char target[100];
int cnt=1,c, n=0;
printf("input source file name and path:");
gets(name);
in = fopen(name, "rb");
if(in == NULL)
{
printf("can not read file
");
return -1;
}
while(!feof(in))
{
sprintf(target, "%s.part%d",name, cnt);
out = fopen(target, "wb");
if(out == NULL)
{
printf("open %d file to write failed
",cnt);
return -1;
}
n = 0;
while((c=fgetc(in)) != EOF && n
fputc(c, out);
n++;
}
fclose(out);
cnt ++;
}
fclose(in);
printf("done! the file is cut to %d file(s)
", cnt-1);
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯