이진 파일을 읽고 해당 내용으로 일부 처리 한 다음 결과를 다른 파일에 쓰는 프로그램을 작성했습니다. 리눅스에서는 완벽하게 작동하지만 Windows에서는 작동하지 않습니다. 출력 파일이 프로그램의 단순화 된 버전입니다Windows의 이진 출력
... 항상 1킬로바이트 있습니다
#include <stdio.h>
void copyFile(char* source, char* dest);
int main (int argc, char* argv[])
{
if (argc != 3)
printf ("usage: %s <source> <destination>", argv[0]);
else
{
copyFile(argv[1], argv[2]);
}
}
void encryptFile(char* source, char* destination)
{
FILE *sourceFile;
FILE *destinationFile;
int fileSize;
sourceFile = fopen(source, "r");
destinationFile = fopen(destination, "w");
if (sourceFile == 0)
{
printf ("Could not open source file\n");
return;
}
if (destinationFile == 0)
{
printf ("Could not open destination file\n");
return;
}
// Get file size
fseek(sourceFile, 0, SEEK_END); // Seek to the end of the file
if (ftell(sourceFile) < 4)
return; // Return if the file is less than 4 bytes
fseek(sourceFile, 0, SEEK_SET); // Seek back to the beginning
fseek(sourceFile, 0, SEEK_SET); // Seek back to the beginning
int currentChar;
while ((currentChar = fgetc(sourceFile)) != EOF)
{
fputc(currentChar, destinationFile);
}
fclose(sourceFile);
fclose(destinationFile);
}
내가 당신에게 문제의 자세한 내용을주고 싶어요,하지만 나는 많은 프로그래밍 경험이없는 C에서 Windows 및 정말 문제가 될 수 있습니다.
이fopen(source, "rb")
fopen(destination, "wb");
I 인해 일부 (
뇌 손상이
가) 주관적인 의사 결정, 입력 스트림에 0x1A에 도달 Win32에서의 파일이 경우 EOF
를 트리거 이해 :
그것은 아마 뇌 손상은 주관적인 - EOF 문자에 대한 이유는 섹터에 파일의 크기의 트랙을 유지 CP/M과 윈도우 선사 시대의 연결로 인해 (또는 클러스터?) 입상 성. –
@Michael Burr 더 많은 정보가 있으면 정말 좋겠다. – cnicutar
더 많은 정보가 없습니다 - CP/M은 디스크에 텍스트 파일이 얼마나 많은 섹터를 차지했는지 알았습니다. 마지막 섹터에서 데이터를 읽는 것을 멈추어야 할 때, 센티넬 EOF 값이 사용되었고 ctrl-Z가 센티넬이되도록 선택했습니다. MS-DOS는 CP/M과 어느 정도의 호환성을 제공했기 때문에 동일한 구성표를 지원했습니다. 그리고 Windows가 많은 DOS 수하물을 가져 왔기 때문에, 여기 있습니다. –