I would like to know how to pre-define the size of an array inside a struct of the form:
struct exemplo{
int l;
int c;
int matriz[l][c];
};
The compiler complains that l and c in the array row is not declared here.
I would like to know how to pre-define the size of an array inside a struct of the form:
struct exemplo{
int l;
int c;
int matriz[l][c];
};
The compiler complains that l and c in the array row is not declared here.
When working with a vector, it must be borne in mind that there are two types: static vectors and dynamic vectors. The vector of your struct in case is a static vector, you can even declare it and use it (if your code and logic are correct, of course), but the size of that vector must be declared by you, programmer. And how to do that? With #define preprocessing commands:
#define j 10
Now, when I can use j to declare a static vector, however, the user will not interfere in any moment, after all, they are preprocessing commands. I recommend this if that's what you want to do.
If you want a user intervention on the vector size, you will need a dynamic vector:
char *vetor = (char *) malloc(100 * sizeof(char));
If you would like to learn more about dynamic allocation, I recommend accessing this link .