I need to pass in a 2D area (a matrix) from the command line through a txt file that looks like this:
0 0 0 0 0
0 1 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 0 0 0
I'm using C and need to have it in row-major order, so I'm trying to do this:
int matrix[][] = argv[2]; // it is the second command line argument passed
This isn't working, is it because it needs to be a 1-dimensional array? Am I only allowed to use a regular 1D array for row-major ordering? The error I'm getting is "array type has incomplete element type 'int[]' "
because this is invalid, out of the missing ';' :
Considering argv[2] is the pathname of the file containing the 5x5 matrix the declaration of the matrix can be :
and you need to read the values in the file to set the matrix's content, you cannot directly map the txt file to matrix
Example :
Compilation and execution: