title: What in my program is causing exception c0000005? (Probably a memory error)
body: <p>My code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint-gcc.h&gt;
  #include &lt;string.h&gt;
  
  int checkAnagram(char *word1, char *word2, int length){ //This function compares the two strings by storing the occurrences of their letters in a histogram, and then comparing that histogram.
      printf("test4");
      int i, n;
      int letterCount1[26], letterCount2[26];
      char letter;
      for(i=0;i&lt;length;i++){
          letter = word1[i];
          letterCount1[letter-'a']++;
      }
      for(n=0;n&lt;length;n++){
          letter = word2[n];
          letterCount2[letter-'a']++;
      }
  
      for(i=0;i&lt;26;i++){
          for(n=0;n&lt;26;n++){
              if(letterCount1[i]==letterCount2[n]){
                  i++;
          } else {
          return 0;}
      }
  }
  return 1;
  }
  
  void main(){
      int length1, length2,i,n;
  
      scanf("%d", &amp;length1);
      int lengthArray1[length1]; //Array used to store the length of each string (without white spaces)
      char *sentenceArray1[length1];
      char tempString[100000];
      //The array for storing the first set of sentences, and a temporary string used
      //for allocating memory in the next loop
      for(i=0;i&lt;=length1;i++){
          fgets(tempString, 100000, stdin); //Reads the first line of input (up to and including \0), with a maximum line length which will probably be sufficient.
          sentenceArray1[i]=malloc((strlen(tempString))*sizeof(char)); //Allocates just enough memory for each string (including \0).
          int index = 0;
          for(n=0;n&lt;(strlen(tempString));n++){
              if(tempString[n] != ' ' &amp;&amp; tempString[n] != '.') { //Copies only from the input if the character is not a whitespace.
                  sentenceArray1[i][index++]=tolower(tempString[n]);
              }
          }
          sentenceArray1[i][index] = '\0';
          lengthArray1[i]=strlen(sentenceArray1[i]);
          printf("test1\n");
      }
      scanf("%d", &amp;length2);//Same stuff as above, now for the second set of strings.
      int lengthArray2[length2], index;
      char *sentenceArray2[length2];
      for(i=0;i&lt;=length2;i++){
          fgets(tempString, 100000, stdin);
          sentenceArray2[i]=malloc((strlen(tempString))*sizeof(char));
          index = 0;
          for(n=0;n&lt;(strlen(tempString));n++){
              if(tempString[n] != ' ' &amp;&amp; tempString[n] != '.') {
                  sentenceArray2[i][index++]=tolower(tempString[n]);
              }
          }
          sentenceArray2[i][index] = '\0';
          lengthArray2[i]=strlen(sentenceArray2[i]);
          printf("test2\n");
      }
      printf("test3");
      for(i=0;i&lt;length1;i++){
          for(n=0;n&lt;length2;n++){
              if(lengthArray2[i]==lengthArray1[i]){
                  if(checkAnagram(*sentenceArray1[n],*sentenceArray2[i], length1)==1){ //Sends strings only to the checkAnagram function if they are of the same length.
                      printf("%d ",i);
                  }
              }
          }
          printf("\n");
      }
  
  }
  </code></pre>
  
  <p>Supposed input and output:
  <img src="https://i.stack.imgur.com/DzpI9.png" alt="I/O"></p>
  
  <p>I must have messed something up with the arrays and pointers somewhere, but the limited feedback from my console + my limited experience with C programming makes it hard to locate the error. My output gets as far to print "test4" once, and then crashes with the exception given in the title.</p>
  
  <p>I hope what I want to achieve is clear, but I can't be any more precise on the error, unfortunately.</p>