int main()
{
FILE *fe, *fs;
unsigned char buffer[128];
int bytesreader;
int i;
char cad[100];
fe = fopen("pg2000.txt", "rb");
fseek(fe, 0L, SEEK_END);
int x = ftell(fe);
printf("%d",x);
int x = ftell(fe);
int result=x/128;
for(i=0;i<result;i++)
{
bytesreader = fread(buffer, 1, 128, fe)
sprintf(cad, "a%d", i);
strcat(cad,".txt");
printf("%s\n", cad);
fs = fopen(cad, "wb");
fwrite(buffer, 1, bytesreader, fs);
fclose(fs);
}
fclose(fe);
return 0;
}
我想将一个文件分成相等的部分,每个部分 128 字节,但是当文件很大时我会遇到访问冲突,我不明白......
最佳答案
fe = fopen("pg2000.txt", "rb");
int x = ftell(fe);
int result=x/128;
x
这里将为零。如果 fopen()
成功。您需要检查哪些内容。
此外,正如 WhozCraig 指出的那样,fs
的 fclose()
应该在您的循环中。
还有这个
for(i=0;i=result;i++)
^
可能也不完全是您的想法。
关于c - 将文件分成相等的部分,每个部分 128 字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19213851/