首先你必须知道具体是从那一byte到哪一byte要删除。
假设那个文件有50byte大,你要把从10到20byte之间的资料删除:
int deleteStart = 10;
int deleteEnd = 20;
FILE * inFile = fopen("myfile", "rb" );
FILE * outFile = fopen("myNewFile", "wb" );
void *buffer = malloc(1);
fseek(inFile, 0 ,SEEK_END);
long fileSize = ftell (inFile);
rewind (inFile);
long byteRead = 0;
while(true)
{
if (byteRead == fileSize)
break;
fread(buffer, 1, 1, inFile);
byteRead++;
if (byteRead < deleteStart || byteRead > deleteEnd)
fwrite(buffer, 1, 1, outFile);
}
fclose(inFile);
fclose(outFile);
重来没有这么做过,不知道对不对... :D |