我正在制作一个逐行处理文本文件的程序,但文件的第一行是一个单一的 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)
编辑:对于那些说我没有使用变量的人,我稍后在代码中使用了它