I am passing a vector to a function. Program is compiling but when I am running it, it is showing segmentation fault(core dump). : <p>I want to sort a text file using merge sort. I am using vector to process the text file. This program is compiling correctly but when I am running it, it is showing segmentation fault(core dumped) error. I tried many thing but all in vain. Can anyone help me in this. Thanks in advance.</p>

<pre><code>vector&lt;string&gt; sV;
void merge(vector&lt;string&gt; &amp; sV, int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

   vector&lt;string&gt; sV1;
   vector&lt;string&gt; sV2; 

    for (i = 0; i &lt; n1; i++)
    sV1[i] = sV[l+1];  
    for (j = 0; j &lt; n2; j++)
    sV2[j] = sV[m + 1 + j]; 

    i = 0; 
    j = 0; 
    k = l; 
   while (i &lt; n1 &amp;&amp; j &lt; n2)
    {
      if (sV1[i] &lt;= sV2[j])  
       {
        sV[k] = sV1[i]; 
        i++;
       }
      else
        {
        sV[k] = sV2[j];   
        j++;
        }
    k++;
    }

   while (i &lt; n1)
   {
    sV[k] = sV1[i];     
    i++;
    k++;
   }
   while (j &lt; n2)
   {
    sV[k] = sV2[j];   
    j++;
    k++;
   }
 }

void mergeSort(vector&lt;string&gt; &amp; sV, int l, int r)
   {
    if (l &lt; r)
     {
      int m = l+(r-l)/2;
      mergeSort(sV, l, m);
      mergeSort(sV, m+1, r);
      merge(sV, l, m, r);
     }
   }

int main() 
  {
   string word;
   char ch, ch1;

  ifstream tin("a1.txt");
  ofstream outp("out.txt");
  if(!tin.is_open())
     cout &lt;&lt; "Unable to open file :) \n";

  while(tin &gt;&gt; word)
     sV.push_back(word);

  mergeSort(sV, 0, sV.size() - 1);
  for (size_t i = 0; i &lt; sV.size(); i++) {
    outp&lt;&lt; sV[i] &lt;&lt; " ";
  }
 return 0;
}
</code></pre>
