I am new to C, and I am trying to initialize array elements at run time, according to user input (so if the user inputs 4, then array[0]=4).
I have the following code:
#include<stdio.h>
#define MAX 10
#define maxValue 100
int array[MAX];
int n;
int main(void){
   scanf("%d", n); //asks for array value
   if (n <= maxValue)
   {
      array[0] = n;
   }
   return 0;
}
The code compiles, but triggers an access violation. What's wrong?
scanf().-Wallto catch a large variety of such errors. Other compilers will probably need other options.