I'm fairly new to programming so bear with me here please.
I am trying to create a global array with user-defined dimensions.
the code is:
Code:
int matr_size()
{
int x = 0;
printf("Please enter the number of nodes: ");
scanf( "%d", &x);
printf("There are %d nodes in this simulation.", x);
getchar();
return x;
}
const int nodes = matr_size();
float A_inv[nodes - 1][nodes - 1];
A_inv[][] is then filled out in a function called matinv() and used later in main()
I am getting errors:
pyrol1.c:57:22: error: array bound is not an integer constant before ‘]’ token
pyrol1.c:57:33: error: array bound is not an integer constant before ‘]’ token
pyrol1.c: In function ‘int main()’:
pyrol1.c:159:18: error: ‘A_inv’ was not declared in this scope
pyrol1.c: In function ‘void matinv()’:
pyrol1.c:205:11: error: ‘A_inv’ was not declared in this scope
pyrol1.c:287:11: error: ‘A_inv’ was not declared in this scope
I'm pretty sure I read that an array cannot be defined by a variable in C so I assume that is the issue, but I'm not sure how else to do it. Previously the size was defined by #define NODES and it worked fine but I need this user input. Any advice?
Thanks