It is better to deal with a matrix when it is represented as a two-dimensional array.
Instead of calling malloc
and then memset
manually you can substitute them for a call of calloc
.
So you can write in main (there is no need to declare the pointer in the file scope)
int ( *matrix )[COL] = calloc( 1, sizeof( int[ROW][COL] ) );
Using such an array makes code more clear. For example to output the matrix you can write
for ( size_t i = 0; i < ROW; i++ )
{
for ( size_t j = 0; j < COL; j++ )
{
printf( "%d ", matrix[i][j] );
}
putchar( '\n' );
}
To conclude about difficulties of using a one-dimensional array imagine how will look a code of multiplication of two matrices.