title: array length variable - c
body: <p>i'm writing a c program and i've noticed that whenever i declare my array length with const variable(const size_t MAX_LEN  = <em>some number</em>) it sends me errors.
  on the other hand, when i'm using (#define MAX_LEN = <em>some number</em>) as my array length declaration it works just fine.</p>
  
  <p>the exact error i get : LinSeperator.c:45:2: error: variable length array ‘arr’ is used [-Werror=vla]
    double theAns, arr[MAX_LEN];
    ^</p>
  
  <p>could anyone help me figure out why it happens?</p>
  
  <p>EDIT: here's my code: 
  this is my LinSeperatorHelperFunc.h:</p>
  
  <pre><code>#pragma once
  #include &lt;stdio.h&gt;
  
  const size_t MAX_LEN = 199;
  
  typedef struct Orange
  {
  double arr[MAX_LEN];
  int tag;
  }orange;
  
  
  void learnProg(orange *o, double w[], int d);
  
  void filePrinter(const char *output, FILE **fileIn, int d, double w[]);
  </code></pre>
  
  <p>this is my .c file:</p>
  
  <pre><code>#include "LinSeperator.h"
  #include "LinSeperatorHelperFunctions.h"
  #define NEG_ONE (-1)
  #define NegToPos (2)
  
  
  
  
  void LinSeperator(const char *In, const char *Out){
  FILE * input;
  orange o;
  int d , pos, neg ,i , j;
  //initializing the hypothesis vector as requested in step 1
  double w[MAX_LEN];
  for(i = 0 ; i&lt;MAX_LEN ; i++){
      w[i] = 0;
  }
  input = fopen(In,"r");
  if(input == NULL){
      printf("file doesnt exists");
      return;
  }
  fscanf(input, "%d %d %d", &amp;d , &amp;pos, &amp;neg);
  
  for(i = 0; i&lt;pos+neg ; i++){
      o.tag = i&lt;pos ? 1: -1;
  
      for(j = 0 ; j&lt;d ; j++){
          fscanf(input, "%lf", &amp;o.arr[j]);
          //removing ',' from being scanned
          if(j!= d-1){
              fgetc(input);
          }
      }
      learnProg(&amp;o,w,d);
  }
  filePrinter(Out, &amp;input, d, w);
  fclose(input);
  
   }
  
  void filePrinter(const char* out, FILE **in, int d, double w[]){
  int i;
  double theAns, arr[MAX_LEN];
  FILE *output = fopen(out, "w");
  if (output == NULL){
      printf("couldnt write to the current file");
      return;
  }
  while(!feof(*in)){
  
      for (i=0; i&lt;d; i++) {
          fscanf((*in), "%lf", &amp;arr[i]);
          if(feof(*in))//if we finished the checked vectors we should finish the file and the function 
          {
              fclose(output);
              return;
          }
          //preventing from reading the "," between each col
          if(i!=d-1){
              fgetc(*in);
          }
      }
      theAns=0;
      for (i=0; i&lt;d; i++){
          theAns+=arr[i]*w[i];
      }
          //if ans &gt;=0 print 1 to file else -1
      fprintf(output, "%d\n", NEG_ONE+NegToPos*(theAns&gt;=0)); 
  }
  fclose(output);
    }
  
  
  
  
   //the learning progress algo
    void learnProg(orange *o, double w[], int d){
  int i, negOrPos = (*o).tag;
  double theAns = 0;
  for(i = 0; i&lt;d ; i++){
      theAns += ((*o).arr[i] * w[i]); //2.1
  }
  //has the same sign
  if( (negOrPos * theAns) &gt; 0 ){  //2.2
      return ;
  }
  else{
    for(i = 0; i&lt;d ; i++){
        w[i] += (negOrPos * (*o).arr[i]);
    }
  }
  }
  </code></pre>