title: Problems using malloc() to delete array within for loop
body: <p>I have an array of data, <code>arr</code>, and an array of indexes, <code>index</code>. My goal is to use a for loop to create new arrays of data partitioned at each of the indexes and to further find the minimum in each partitioned array. I am using <code>malloc</code> to create a dynamic array which I then free at the end of each loop. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
   int main(void)
   {
       int j;
       int arr[] = {1,3,4,6,7,8,12,87,89,12,34,43,54,67,81,2,0,10,23,45,81,23,89,23,56,81,28,79};
       int index[] = {1,5,9,13,19,24};
       int h = 27;
       int k;
       int c;
       for(j = 0;j &lt; h - 1;++j)
       {         
           int *temp_arr = malloc(10*sizeof(int));
           for(k = index[j];k&lt;(index[j+1]);++k )
           {
               temp_arr[k] = arr[k];
           }
           int local_min ;
           local_min = temp_arr[0];
           for ( c = 1 ; c &lt; sizeof(temp_arr) / sizeof(temp_arr[0]) ; c++ )
           {    printf("Temp array %d ", temp_arr[c]);
               if ( temp_arr[c] &lt; local_min)
               {
                   local_min = temp_arr[c];
                   printf("Local min in loop %d ", local_min );
               }          
           }
           free(temp_arr);
           printf("\n");
  
      }
      return 0;
   }
  </code></pre>
  
  <p>Unfortunately, the program is crashing without giving me any error messages. I think that I may have done something fundamentally wrong using <code>malloc</code>. Any suggestions on how to correctly do this would be greatly appreciated.</p>