Hi
I write function that take 5 parameters: pointer to array a, pointer to array b, size of array a, size of array b and pointer to size of result array
My task is to sort first array remove duplicates, this same with second array and include this two array. My code below

Code:
#include <stddef.h>
#include <stdlib.h>
int compare(const void *a, const void *b)
{
  return *(int*)a-*(int*)b;
}


int *testit(const int *a, const int *b, size_t az, size_t bz, size_t *cz) {
int *res;
size_t i,j;
qsort(a,az,sizeof(int),compare);
qsort(b,bz,sizeof(int),compare);


res=(int*)malloc(sizeof(int)*(az+bz));
for(i=0,j=0;i<az;)
{
  if(a[i]!=a[i+1])
    res[j++]=a[i++];
  if(a[i]==a[i+1])
  {
    while((a[i]==a[i+1])&&(i<az))
      i++;
    res[j++]=a[i++];
  }
 }
for(i=0;i<bz;)
{
  if(b[i]!=b[i+1])
    res[j++]=b[i++];
  if(b[i]==b[i+1])
  {
    while((b[i]==b[i+1])&&(i<bz))
      i++;
    res[j++]=b[i++];
  }
 }
 *cz=j;
 qsort(res,*cz,sizeof(int),compare);
return res;
}
I got some errors from server
Code:
ERROR < incorrect array length > 
Array a:   {1} 
Array b:   {2, 3, 4} 
Expected:  {1, 2, 3, 4} 
Submitted: {1, 1, 2, 3, 4}
Can you tell me where is mistake