エラーとして「'read_file' の前にイニシャライザが必要です。エラーは "instruction code[] read_file(instruction code[])" の行にあります。そのオンライン ヘルプを求めて Web を検索していますが、見つかったのはすべて c++ です。関連する投稿なので、これを明確にするために、これは C 用です。
関数プロトタイプの位置を移動しようとしました。以前、配列の代わりにリンク リストを実装した同じプログラムを作成しましたが、エラーは発生しなかったので、構造体配列と関係があるのではないかと考えています。
助けてくれてありがとう。
#include<stdio.h>
#include <stdlib.h>
typedef struct instruction{
int op; //opcode
int l; // L
int m; // M
} instr;
FILE * ifp; //input file pointer
FILE * ofp; //output file pointer
instruction code[501];
instruction code[] read_file(instruction code[]);
char* lookup_OP(int OP);
void print_program(instruction code[]);
void print_input_list(instruction code[]);
int main(){
code = read_file(code);
print_input_list(code);//used for debugging
print_program(code);
}
instruction code[] read_file(instruction code[]){
int i = 0;
ifp = fopen("input.txt", "r");
while(!feof(ifp)){
fscanf(ifp,"%d%d%d",&code[i]->op, &code[i]->l, &code[i]->m);
i++;
}
code[i]->op = -1; //identifies the end of the code in the array
fclose(ifp);
return code;
}