title: Why merge sort with multiple strings using strcmp is not a proper method
body: <p>I am trying to external merge multiple files that contain sorted string(base 
  on strcmp)
  but I encounter a problem when using external merge sort .</p>
  
  <p>It seems that my merge sort method is not properly functioning , though the data is proper read into the<code>mergeSort()</code>,and the algorithm is just a typical iterative merge , I think maybe because that the strcmp is not proper in this case of sorting? </p>
  
  <p>and the code below is the segment of my code and
  I have changed the external merge to internal merge to test it ,but it still not working.  </p>
  
  <pre><code>/* Iterative C program for merge sort */
  #include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;time.h&gt;
  
  /* Function to merge the two haves arr[l..m] and arr[m+1..r] of array arr[] */
  void merge(char  arr[][300], int l, int m, int r);
  // Utility function to find minimum of two integers
  int min(int x, int y) { return (x&lt;y)? x :y; }
  /* Iterative mergesort function to sort arr[0...n-1] */
  void mergeSort(char arr[][300], int n )
  {
     int curr_size;  // For current size of subarrays to be merged
                     // curr_size varies from 1 to n/2
     int left_start; // For picking starting index of left subarray
                     // to be merged
     for (curr_size=1; curr_size&lt;= n-1 ; curr_size = 2 * curr_size ){
         // Pick starting point of different subarrays of current size
         for ( left_start=0 ; left_start &lt; n-1 ; left_start += 2 * curr_size ){
             // Find ending point of left subarray. mid+1 is starting
             // point of right
             int mid = left_start + curr_size - 1;
             int right_end = min( left_start + 2 * curr_size - 1 , n-1);
             if( mid &gt; n-1 ){
                 mid = (left_start+right_end)/2;
             }
  
             // Merge Subarrays arr[left_start...mid] &amp; arr[mid+1...right_end]
             merge(arr, left_start, mid, right_end);
         }
     }
  }
  
  /* Function to merge the two haves arr[l..m] and arr[m+1..r] of array arr[] */
  void merge( char arr[][300] , int l , int m , int r )
  {
      int i, j, k;
      int n1 = m - l + 1;
      int n2 =  r - m;
      /* create temp arrays */
      char L[n1][300] , R[n2][300];
      /* Copy data to temp arrays L[] and R[] */
      for (i = 0; i &lt; n1; i++)
          strcpy( L[i] , arr[l + i] );
      for (j = 0; j &lt; n2; j++)
          strcpy( R[j] , arr[m + 1+ j] );
      /* Merge the temp arrays back into arr[l..r]*/
      i = 0;
      j = 0;
      k = l;
      while (i &lt; n1 &amp;&amp; j &lt; n2){
          if ( strcmp( L[i] , R[i] ) &lt;= 0 ){
              strcpy( arr[k] , L[i] );
              i++;
          }
          else{
              strcpy ( arr[k] , R[j] );
              j++;
          }
          k++;
      }
      /* Copy the remaining elements of L[], if there are any */
      while (i &lt; n1){
          strcpy( arr[k] , L[i] );
          i++;
          k++;
      }
      /* Copy the remaining elements of R[], if there are any */
      while (j &lt; n2){
          strcpy( arr[k] , R[j] );
          j++;
          k++;
      }
  }
  /* Function to print an array */
  void printArray(char  A[][300] , int size )
  {
      int i;
      for (i=0; i &lt; size; i++)
          printf("%d:%s \n", i , A[i]);
  }
  /* Driver program to test above functions */
  int main()
  {
      srand(time(NULL));
      FILE **openarray,*output;
      int loop,quantity;
      int tempmumber,allcheck;
      char name[300];
      quantity=20;
      int random;
      char data[quantity][300],*temp,test[300];
  
      printf("initial ok\n");
      for( loop = 0 ; loop &lt; quantity ; loop++)
      {
          random = rand()%900;
          sprintf ( name ,"%d" , random );
          strcpy( data[loop] , name );
          printf("%d:%s\n",loop,data[loop]);
      }
      mergeSort( data , quantity );
  
      printArray( data , quantity );
      return 0;
  }
  </code></pre>
  
  <p>thank for any help you can offer!</p>