テキストファイルを行ごとに処理するプログラムを作成していますが、ファイルの最初の行は、ファイルの長さ (ヘッダー) を示す単一の int です。問題は、ファイルの残りの部分に関する情報を格納する配列を定義しようとしているのですが、city_info と city_dist で未定義のエラーが発生し続けることです。私が見逃しているものはありますか?
コードは次のとおりです。
while(fgets(buffer,MAX_LINE,fp)!=NULL) {
if(firsttime){
int num_city = atoi(buffer);
printf("NUMBER OF CITIES = %d\n",num_city);
node city_info[num_city]; /*compiler says these are undefined*/
int city_dist[num_city]; /*compiler says these are undefined*/
firsttime=FALSE;
}
.
.
.
/*rest of code*/
これが私が得ているコンパイラエラーです:
help.c: In function `main':
help.c:33: warning: unused variable `city_info'
help.c:34: warning: unused variable `city_dist'
help.c:41: error: `city_info' undeclared (first use in this function)
help.c:41: error: (Each undeclared identifier is reported only once
help.c:41: error: for each function it appears in.)
help.c:42: error: `city_dist' undeclared (first use in this function)
編集:変数を使用していないと言っている人のために、後でコードで使用しました