저는 C++ (C#에서 움직이기)에 다소 신참입니다. 그래서 나는 여기서 무슨 일이 일어나고 있는지 정확히 알지 못합니다. 내가 뭘하려는 파일의 이미지를 읽고 그것을 출력 파일에 쓸 때마다,하지만 내가 파일의 일부가 손상된 것처럼 보일 때마다.fwrite() 파일 손상 C++
나는 메모리의 데이터를 검사 해 실제로 일치하기 때문에 범인은 fwrite()로 계속 진행되어야한다고 생각합니다.하지만 항상 잘못된 것일 수도 있습니다. http://pastebin.com/x0eZin6K
그리고 내 코드 : 고급의
// used to figure out if reading in one giant swoop has to do with corruption
int BlockSize = 0x200;
// Read the file data
unsigned char* data = new unsigned char[BlockSize];
// Create a new file
FILE* output = fopen(CStringA(outputFileName), "w+");
for (int i = 0; i < *fileSize; i += BlockSize)
{
if (*fileSize - i > BlockSize)
{
ZeroMemory(data, BlockSize);
fread(data, sizeof(unsigned char), BlockSize, file);
// Write out the data
fwrite(data, sizeof(unsigned char), BlockSize, output);
}
else
{
int tempSize = *fileSize - i;
ZeroMemory(data, tempSize);
fread(data, sizeof(unsigned char), tempSize, file);
// Write out the data
fwrite(data, sizeof(unsigned char), tempSize, output);
}
}
// Close the files, we're done with them
fclose(file);
fclose(output);
delete[] data;
delete fileSize;
감사
는 여기에 몇 가지 샘플 데이터입니다!
Ah! 이진 모드에서는 초기 파일을 열었지만 출력 파일은 열지 않았습니다. 넌 최고야, 고마워! – Lander