[Solved] User input array in C


Better way would be:

int size = 0;
int *aval;

printf("Please enter the size of the array: ");
scanf("%i", &size);
/* Should verify size is reasonable here */

aval = malloc(size * sizeof(*aval));
printf("\n\nPlease enter array values:\n");
for (i = 0; i < size; i++)
{
    scanf("%i", &aval[i]);
}

Doing it this way creates the array in the proper data area, rather than in the local automatic area, which may have limited size. Also, if you are done with the array before the end of the program, then you can free it to recover the space.

solved User input array in C