title: My program segfaults
body: <p>I've been working on this programming assignment for what seems like forever now, and I have yet to figure out my error. Every time I compile the program then input a file I get a segmentation fault (core dumped) error. I'm assuming one of my pointers is pointing to unallocated space, but I have no idea which one. Could someone steer me in the right direction?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;strings.h&gt;
  #include &lt;sys/time.h&gt;
  #define FALSE 0
  #define TRUE !FALSE
  int problem_size;
  
  int Merge (long long int *numbers, int first, int last, int firstOne, int lastOne)
  {
      long long int arrayOne[problem_size];
      long long int arrayTwo[problem_size];
      int x,y;
  
      for (x=0; x&lt;last; x++)
          arrayOne[x] = numbers[x + first];
  
      for (y= last; y&lt; lastOne; y++)
          arrayTwo[y - firstOne];
  
      int i = 0;
      int j = 0;
      int k = first;
  
      while ((i&lt; last-first) &amp;&amp; (j&lt; lastOne - firstOne))
      {
          if (arrayOne[i] &lt;= arrayTwo[j])
          {
              numbers[k] = arrayOne[i];
              i = i+1;
          }
          else
          {
              numbers[k] = arrayTwo[j];
              j = j+1;
          }
          k = k+1;
      }
  
      while (i &lt; last-first)
      {
          numbers[k] = arrayOne[i];
          i = i+1;
          k = k+1;
      }
  
      while(j &lt; lastOne - firstOne)
      {
          numbers[k] = arrayTwo[j];
          j = j + 1;
          k = k + 1;
      }
  }
  
  int MergeSort (long long int *numbers, int low, int high)
  {
      if (high-low &gt; 1)
      {
          int lowest = low;
          int highest = ((high-low)/2) + low;
          int lowestOne = highest;
          int highestOne = high;
  
          MergeSort(numbers, lowest, highest);
          MergeSort(numbers, lowestOne, highestOne);
          Merge(numbers, lowest, highest, lowestOne, highestOne);
      }
  }
  
  int unique3(long long int *numbers, int count, long long int *operations) {
      long long int basic_operations = 0;
      int i;
  
      MergeSort(numbers,0,count);
  
      for (i=0; i &lt; count-2; i++)
          if(numbers[i] == numbers[i+1])
              return FALSE;
      *operations = basic_operations;
      return TRUE;
  }
  
  
  void read_array(char *file_name, long long int **return_numbers, int *return_size) {
      FILE *file; // file pointer used to read in file_name
  
      int count;
      int ii;
      long long int *numbers;
  
      file = fopen(file_name, "r"); // open the file for reading
      if (file == NULL) {
          // error openting the file, print error message
          perror(file_name);
  
          // set pointers to show failed state
          *return_numbers = NULL;
          *return_size = -1;
          return;
      }
  
      // read in the first line to determine how many numbers are in the list
      if (fscanf(file, "%d", &amp;count) != 1) {
          // error openting the file, print error message
          perror("HERE");
          perror(file_name);
  
          fclose(file);
  
          // set pointers to show failed state
          *return_numbers = NULL;
          *return_size = -1;
          return;
      }
  
      // dynamically allocate an array to contain count number of long long ints
      numbers = (long long int *)malloc(sizeof(long long int)*count);
  
      // read in count numbers
      for(ii=0; ii &lt; count; ii++) {
          // read in a number delimited by a comma
          if (fscanf(file, "%lld,", &amp;(numbers[ii])) != 1) {
              // if char_count == -1, there was an error reading
              perror(file_name);
  
              free(numbers);
              fclose(file);
  
              // set pointers to show failed state
              *return_numbers = NULL;
              *return_size = -1;
              return;
          }
      }
  
      fclose(file);
  
      // set up pointer values
      *return_numbers = numbers;
      *return_size = count;
  }
  
  void timing(long long int *numbers, int count, int (*algorithm)(long long int *,
          int, long long int *), long long int *operations, int *unique,
          long long int *ms_time) {
      struct timeval start_tv;
      struct timeval end_tv;
  
      gettimeofday(&amp;start_tv, NULL);
      *unique = algorithm(numbers, count, operations);
      gettimeofday(&amp;end_tv, NULL);
  
      *ms_time = (end_tv.tv_sec - start_tv.tv_sec)*1000000L + (end_tv.tv_usec -
          start_tv.tv_usec);
  }
  
  int main(int argc, char *argv[]) {
      if(argc != 2) {
          printf("Invalid Number of Arguments\n");
          printf("Usage:\n");
          printf("%s &lt;file_name&gt;\n", argv[0]);
          printf("\tfile_name - name of the input file\n");
          printf("It is assumed that the first line of the input file contains\n");
          printf("the count of the numbers in the file. The second line is assume\n");
          printf("to be a comma separated list of integers.\n");
      }
      else {
          int count;
          long long int *numbers;
          long long int operations = 0;
          int is_unique;
          long long int ms_time;
          read_array(argv[1], &amp;numbers, &amp;count);
  
          if(count &gt; 0){
              printf("Here");
              printf("%d ", count);
              timing(numbers, count, unique1, &amp;operations, &amp;is_unique, &amp;ms_time);
              printf("(%d,%lld,%lld) ", is_unique, operations, ms_time);
          }
      }
      return 0;
  }
  </code></pre>