title: How can a simple assignment cause a segmentation fault?
body: <p>I'm making a program to split a file into lexemes but I'm unfamiliar with C and I'm getting a weird segmentation error. The following code runs and prints:</p>
  
  <pre><code>1
  2
  Segmentation Fault: 11
  </code></pre>
  
  <p>I've looked up other causes to segmentation faults and I'm not doing anything to an array after 2. What am I doing wrong? How can a simple assignment cause a segmentation fault?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define CHAR_CODE 1
  #define NUM_CODE 2
  #define RESERVED_CHAR_CODE 3
  #define SPACE_CODE 4
  #define ERR_CODE 5
  
  char token[16];
  char line[128];
  int lineLen = 0;
  int counter = 0;
  FILE *file;
  
  void cleanToken(){
      for(int i = 0 ; i &lt; 16; i++){
          token[i] = 0;
      }
  }
  
  void cleanLine(){
      for(int i = 0 ; i &lt; 128; i++){
          line[i] = 0;
      }
  }
  
  void next(){
      cleanToken();
      printf("1\n");
      char c;
      if(counter == lineLen){
          printf("2\n");
          lineLen = 0;
          printf("3");
          cleanLine();
          printf("4");
          counter = 0;
          while((c=getc(file)) != 10 &amp;&amp; c != EOF){
              if(c!=32){
                  line[lineLen] = c;
                  lineLen++;
              }
              printf("%d\n", lineLen);
          }
          printf("%s\n", line);
      }
      c = line[counter];
      int type = getType(c);
      while(getType(c)==type){
          token[counter] = c; 
          counter = counter + 1;
          c = line[counter];
          if(c == EOF | c == 4 | type == RESERVED_CHAR_CODE){
              break;  
          }
      }
  }
  
  int getType(int c){
      if((c &gt; 96 &amp; c &lt; 123) | (c&gt;64 &amp; c &lt; 91)){
          return CHAR_CODE;
      } else if(c &lt; 58 &amp; c &gt; 46){
          return NUM_CODE;
      } else if(c == 32){
          return SPACE_CODE;
      } else if(c == 33 | c == 34 | (c &gt; 36 &amp; c &lt; 44) | c == 45 | c == 47 | (c &gt; 58 &amp; c &lt; 63)){
  
          return RESERVED_CHAR_CODE;  
      } else {
          return ERR_CODE;
      }
  }
  
  int main(){
      int c;
      FILE* file;
      file = fopen("test.txt", "r");
      for(int i = 0; i &lt; 10 ;i++){
          next();
          printf("%s\n", token);
      }
      return 0;
  }
  </code></pre>