バイナリファイルを読み込み、その内容を処理して結果を別のファイルに書き込むプログラムを作成しました。 Linuxでは完全に動作しますが、Windowsでは動作しません。出力ファイルは常に1キロバイト...Windowsのバイナリ出力
ある。これは、プログラムの簡易版である:私はあなたの問題の詳細を与えるのが大好きだが、私は多くの経験プログラミングを持っていない
#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);
}
WindowsでCと私は本当にどこに問題があるのか分からない。
それはおそらくより多くの脳の損傷は、主観的だ - EOF文字の理由がセクタのみで、ファイルのサイズのトラックを保ったCP/MとWindowsの先史時代の接続によるものである(またはクラスタ?)粒状性 –
@Michael Burrもしあなたがそれについてより多くの情報を持っていれば、私は本当にそれが好きです。 – cnicutar
これ以上の情報はありません - CP/Mは、ディスク上にテキストファイルが占有されているセクタの数を知っていました。最後のセクタからのデータの読み込みをいつ止めるべきかを知るために、センチネルEOF値が使用され、それらはセンチネルであるために「Ctrl-Z」を選択しました。 MS-DOSはCP/Mとある程度の互換性を提供して以来、同じスキームをサポートしていました。 WindowsはDOSの手荷物をたくさん引っ張ってきたので、ここにいるのです。 –