title: Where is the segmentation fault in this program?
body: <p>All this is trying to do is putting the address of shortest string at the beginning and address of longest string at the end of array, but I can't see what is wrong with it. When I run it on linux I get 'segmentation fault'</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  void fx(char* t[], int n);
  
  int main(void) {
      char*t[]= {"horse", "elephant", "cat", "rabbit"};
      int n, i;
      n = sizeof(t)/sizeof(t[0]);
      fx(t, n);
      printf("shortest is %s, longest is %s\n", t[0], t[n-1]);
  
  }
  
  void fx(char* t[], int n) {
      int i;
      char* temp, len0, len1, len;
      len0 = strlen(t[0]); /* lenght of first string*/
      len1 = strlen(t[n+1]); /*lenght of last string*/
      for(i=0; i&lt;n; i++) {
          len = strlen(t[i]); /*temporary lenght if ith string*/
          if( len &lt; len0 ) {
              temp = t[0];  /* if shorter, swap places with first*/
              t[0] = t[i];
              t[i] = temp;
          }
          else if(len &gt; len1) {  /* if larger, swap places with last*/
              temp = t[n-1]; 
              t[n-1] = t[i];
              t[i] = temp;
          }
      }
  }
  </code></pre>