I am working on a merge sort of two files of integers, and am fuzzy on some of the logic\syntax. I need two threads, each of which will open a file, read its contents into an array, and then sort the array using qsort. One thread will operate on file f1.dat(10000 numbers) and leave its sorted contents in array x, while the other will use file f2.dat(11999 numbers) and array y. When the threads have finished, I need to merge x and y into array z so that z is also sorted. Also, I am wanting to use one function for both threads, passing the array, its size, and the name of the file in a structure.

Currently, I have a struct set up with the arrays, their sizes, and the name of the two files, a comparison function for qsort, a sort function for the contents of the files, a merge sort for the z array, and of course the creation of the threads.

I think the biggest area I have questions about is how to properly pass a structure to a generalized sort function and then sort data using that structure parameter.

So far:

Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>

typedef struct Data
&#123;
  int x&#91;10000&#93;;
  int y&#91;12000&#93;;
  int size;
  char *filename;
&#125; data_t;


// Comparison function for qsort
int cmpint &#40;int *a, int *b&#41;
&#123;
  if &#40;*a < *b&#41;
     return -1;
  else
     if &#40;*a > *b&#41;
       return 1;
     else
       return 0;
&#125;


// Sort contents of files
// &#91;B&#93;How to generalize this to work with two separate arrays???????&#91;/B&#93;
void *sort&#40;void *data&#41;
&#123;
  FILE *fp;
  //long lSize = ftell &#40;fp&#41;;
  fp = fopen&#40;filename.x&#91;&#93;, "rb"&#41;;
  fread&#40;x, 10000, size, fp&#41;;

  // data_t *my_data = &#40;data_t *&#41; data;

  qsort&#40;x,1000,sizeof&#40;int&#41;,cmpint&#41;;
  pthread_exit&#40;0&#41;;

&#125;


int main&#40;&#41;  &#123;

  int i=0,j=0,k=0;
  char z&#91;22000&#93;;
  pthread_t px, py;

  pthread_create&#40;&px, NULL, sort, &#40;void *&#41; &data_x&#41;;
  pthread_create&#40;&py, NULL, sort, &#40;void *&#41; &data_x&#41;;

  pthread_join&#40;px, 0&#41;;
  pthread_join &#40;py, 0&#41;;

  // Merge x and y into z, sorted
  while &#40;i<1000 || j < 1000&#41;
  &#123;
    if &#40;j == 1000&#41;
       z&#91;k++&#93;=x&#91;i++&#93;;

    else
       if &#40;i<1000 && &#40;x&#91;i&#93;<y&#91;j&#93;&#41;&#41;
          z&#91;k++&#93;=x&#91;i++&#93;;
    else
          z&#91;k++&#93;=y&#91;j++&#93;;
  &#125;


&#125;