The program does not deal with an undimensioned matrix, at some point the dimensions are known and at that point they should be stored in suitable variables for later use.
If this is a C program then rather than a pointer int ** or float ** to hold your matrix you might want to consider a structure like
-
struct matrix {
-
int xdim;
-
int ydim;
-
float **data;
-
};
-
So the matrix dimensions are carried with the matrix data at all times.