i was watching an exercise in my textbook that says: Create a C program that take from the keyboard an array with length \"N\".
The question is: In C language, how can i
Do not create an array of undefined length.
After getting the needed length N
, if C99 use a VLA (Variable Length Array)
int A[N];
... or allocate memory
int *A = malloc(sizeof *A * N);
...
// use A
...
free(A);
[Edit]
Good to add validation on N
before proceeding. Example:
if (N <= 0 || N >= Some_Sane_Upper_Limit_Like_1000) return;