I have an issue that I cannot seem to find the answer to other than perhaps a few "its not possible's" but it absolutely has to be possible so I figured I'd try to explain.
Essentially I have a problem where I read in a number of iterations A from a file then sizes x and y. In a function I pass x and y like so:
//Really bad pseudocode
main(){
int i;
ifstream input;
input.open("somefile")
input >> A;
input >> x;
input >> y;
for(i = 0; i < A; i++){
somefunc(x,y);
}
...}
somefunc(int x, int y){
int matrix[x][y];
...
someotherfunc(matrix);
...}
someotherfunc(int matrix[][]){
...
someotherfunc(matrix[index][otherindex]);
...}
So my question is this, how can I make the call to "someotherfunc" above work. I use x and y as the size of the variable sizes for the matrix. Those change per iteration A. On one run it may be made as int matrix[1][10]. then on another maybe matrix[100][999] or matrix[999][1235415] and so on.
What kind of trick, I don't care how "bad practice" it is, can make this work? I have tried circumventing using a matrix that has an int** member that gets dynamically allocated in "somefunc" but assignment to it won't work for whatever reason. I need to be able to define a multidimensional array (matrix) and pass it between functions, particularly in a recursive manner. I have been on this for hours and have made no headway.
Before it is mentioned, I am quite well aware I left out checks for whether the file was successfully opened, I purposely did so as it has absolutely nothing to do with my issue.
I have found really mixed answers to this question but surely there has to be some solution.
Further information on this is I have no way of knowing ahead of time what the max X or Y will be that gets input.
I suppose I could use constant globals like 2147483647 (max value of a signed int) and initialize the matrix like 'int matrix[2147483647][2147483647]' but that seems like an almost obscene waste of space and surely there has to be a better way to do this.