我正在尝试将文本文件的第二行和第三行中的10个整数存储到整数数组中。当我尝试编译时,我得到关于某些变量未声明的多个错误。
输入是分配给输入.txt文件的名称。
perm1和perm2都是大小为[10]的int数组。
int current_line = 0; //a line counter
while(fgets(line, 401, Input) != NULL){
if(current_line == 1){
sscanf(line, "%d %d %d %d %d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9, &n10);
perm1[0] = n1;
perm1[1] = n2;
perm1[2] = n3;
perm1[3] = n4;
perm1[4] = n5;
perm1[5] = n6;
perm1[6] = n7;
perm1[7] = n8;
perm1[8] = n9;
perm1[9] = n10;
}
else if(current_line == 2){
sscanf(line, "%d %d %d %d %d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9, &n10);
perm2[0] = n1;
perm2[1] = n2;
perm2[2] = n3;
perm2[3] = n4;
perm2[4] = n5;
perm2[5] = n6;
perm2[6] = n7;
perm2[7] = n8;
perm2[8] = n9;
perm2[9] = n10;
}
else{
//do nothing
}
current_line++;
}
当我编译这段代码时,它告诉我“line”是未声明的。它还告诉我n1,n2,n3等都是未声明的。
我该如何解决这个问题?