私のプログラムは.txtファイルでは問題はありませんが、私のプログラムは別のファイル拡張子を持つテキストファイルを読み込む必要があります(.emuが必要です) 。単純に同じファイルの拡張子を.emuに変更すると、変数 'file'はNULLであるため、ファイルは開かれません。Cで異なる拡張子を持つ.txtファイルを読む
は周り少し見ていたので、解決策を見つけることができていない任意のヘルプは非常に
を高く評価され、ここでソースコードがあります:
void handleArgs (const char *filename, int trace, int before, int after) {
FILE *file = fopen(filename, "r");
char *address = malloc(MAX_ADD_LENGTH * sizeof(char));
char *instruction = malloc(MAX_INS_LENGTH * sizeof(char));
long int addressDecoded;
if (file == NULL || file == 0) {
fprintf(stderr, "Error: Could not open file");
}
else {
if (ferror(file) == 0) {
while (fscanf(file, "%s %s", address, instruction) != EOF) {
if (strlen(address) == 8 && strlen(instruction) == 8) {
addressDecoded = strtol(address, NULL, 16);
printf("%ld\n", addressDecoded);
//instruction = decodeInstruction(instruction);
}
else {
fprintf(stderr, "Error: particular line is of wrong length");
}
}
}
}
fclose(file);
}
引数「ファイル名」実行時は単に '/foopath/test.emu'
ファイルハンドルを開くソースコードを投稿できますか? –
いくつかコードを投稿できますか?ファイルを開こうとするとそこにファイルがありますか?拡張機能は 'fopen'には何の影響もありませんので、何か別のものがあるはずです。 – rlc
あなたの問題は拡張機能ではありません。 –