我必须从我从文件中读取的内容更改在主函数中定义为全局变量的整数数组的值,读取过程是 k,char 与“x”字符串的比较是 k,但是在数组的位置 i 上分配新值不起作用。
//global variable
int matrix[55];
static void main()
{
FILE *readFile;
char *caracter;
readFile = fopen(fileName,"r");
int i;
if (readFile == NULL)
{
g_print ("\nError");
}
else
{
while (caracter != EOF)
{
caracter = fgetc(archivo);
if (caracter == '*')
matrix[i] = 1;
if (caracter == ' ')
matrix[i] = 2;
if (caracter == '+')
matrix[i] = 3;
if (caracter == 'S')
matrix[i] = 4;
if (caracter == 'S')
matrix[i] = 5;
if (caracter == 'R')
matrix[i] = 6;
else
matrix[i] = 7;
i++;
g_print ("%d", mapaJuego[i]);
}
}
}