I am trying to solve a problem that i need to work with 2D array which size i read from a txt file. In order to create a 2D array "V" needs const int and later V needs to passed in print function which means it has to be global too in my implementation. What would be possible solutions for this?
void printAdjMatrix(int arr[][V])
{
for (int i = 0; i < V; i++)
{
for (int j = 0; j < V; j++)
{
printf("%d ", arr[i][j]);
}
printf("\n");
}
}
int main()
{
fstream in("in.txt", ios::in);
int vort;
in >> vort;
const int V = vort;
int adjMatrix[V][V]; //error: expression must have a constant value
printAdjMatrix(adjMatrix);
}