0
我用fseek和fread函數讀取文件的指定塊,然後將其寫入另一個文件。出於某種原因,在目標文件中,每個寫入的塊之間會有大約20個字節的重疊。fseek()導致數據重疊
請問誰能幫我找出這個垃圾的來源?這肯定是由fseek函數造成的,但我不知道爲什麼。
FILE *pSrcFile;
FILE *pDstFile;
int main()
{
int buff[512], i;
long bytesRead;
pSrcFile = fopen ("test.txt" , "r");
pDstFile = fopen ("result1.txt", "a+");
for(i = 0; i < 5; i++)
{
bytesRead = _readFile (&i, buff, 512);
_writeFile(&i, buff, bytesRead);
}
fclose (pSrcFile);
fclose (pDstFile);
}
int _readFile (void* chunkNumber, void* Dstc, long len)
{
int bytesRead;
long offset = (512) * (*(int*)chunkNumber);
fseek(pSrcFile, offset, SEEK_SET);
bytesRead = fread (Dstc , 1, len, pSrcFile);
return bytesRead;
}
int _writeFile (void* chunkNumber, void const * Src, long len)
{
int bytesWritten;
long offset = (512) * (*(int*)chunkNumber);
bytesWritten = fwrite(Src , 1 , len , pDstFile);
return bytesWritten;
}