Radix Sorting Algorithm in c : <p>I have been tried to write radix sort in c.when i run my code with the static array it works well. but when i am trying to take random inputs from file it gives me an "Segmentation fault" at run time.help Please just help to modify this code
here is my code:</p>

<pre><code> #include &lt;stdio.h&gt;
 #include &lt;stdlib.h&gt;
 #include&lt;math.h&gt;
 #include&lt;string.h&gt;
 int getMax(int arr[], int n)
 {
    int mx = arr[0];
    int i;
    for (i = 1; i &lt; n; i++)
      if (arr[i] &gt; mx)
        mx = arr[i];
    return mx;
 }
 void countSort(int arr[], int n, int exp,int base)
 {
   int output[n]; 
   int i;
   int count[base];
   memset(count, 0, sizeof count);
   for (i = 0; i &lt; n; i++)
     count[ (arr[i]/exp)%base]++;
   for (i = 1; i &lt; base; i++)
     count[i] += count[i - 1];
   for (i = n - 1; i &gt;= 0; i--)
   {
     output[count[ (arr[i]/exp)%base ] - 1] = arr[i];
     count[ (arr[i]/exp)%base ]--;
   }
   for (i = 0; i &lt; n; i++)
     arr[i] = output[i];
 }
void radixsort(int arr[], int n,int base)
{
  int m = getMax(arr, n);
  int exp;
  for (exp = 1; m/exp &gt; 0; exp *= 10)
    countSort(arr, n, exp , base);
}
void print(int arr[], int n)
{
  int i;
  for (i = 0; i &lt; n; i++)
    printf("%d ",arr[i]);
}
int main(int argc,int argv[])
{
  int base=atoi(argv[1]);
  int num,i;
  FILE *fp1=fopen("myFile1.txt","r");
  int arr[50];
  while(fscanf(fp1,"%d",&amp;num)==1)
  {
        arr[i]=num;
        i++;
  }
  int n = sizeof(arr)/sizeof(arr[0]);
  radixsort(arr, n ,base);
  print(arr, n);
  fclose(fp1);
  return 0;
}
</code></pre>
