I have this part of code:
for(i = 0; i < matrix->y; i++)
{
printf("3.%i - %i %i\n", i, matrix->y, matrix->x);//write correct "3.0 - 3 4"
for(j = 0; j < matrix->x; j++)
{
printf("N - %i %i\n", matrix->y, matrix->x);//never write anything
fscanf(input, "%i", &grid[i][j]);
}
printf("3.%i - %i %i\n", i, matrix->y, matrix->x);//write wrong "3.0 - 3 0"
}
first printf outputs y=3 and x=4, but it never goes inside loop, it never reach the second printf inside for-loop. When I write the same printf from the first line after for-loop, it tels me y=3 and x=0. Where I have done mistake.
Thanks.
Edit
Code is writen as it is. No lines skipped.
Matrix definition
typedef struct matrix
{
int x;
int y;
int ** grid;
} Matrix;
i and j is defined by
int i, j;
Whole function
Matrix * loadMatrix(char * filename)
{
Matrix * matrix;
FILE * input;
input = fopen(filename, "r");
if (input == NULL)
printError (ERR_READFILE);
else
{
fscanf(input, "%i", &(matrix->y));
fscanf(input, "%i", &(matrix->x));
int i, j;
int grid[matrix->y][matrix->x];
matrix->grid = grid;
printf("2 - %i %i\n", matrix->y, matrix->x);
for(i = 0; i < matrix->y; i++)
{
printf("3.%i - %i %i\n", i, matrix->y, matrix->x);
for(j = 0; j < matrix->x; j++)
{
printf("N - %i %i\n", matrix->y, matrix->x);
fscanf(input, "%i", &grid[i][j]);
}
printf("3.%i - %i %i\n", i, matrix->y, matrix->x);
fclose(input);
}
return matrix;
}