#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <proto/dlg.h>
int   dosort(char *, char *);

extern struct Library *DLGBase;

int BuildArray(char **array,char *element,int size,int elementnum,int numelements)

{char *temparray;
 long  count;

 if (!element)
    {qsort(*array, elementnum, size, dosort);
     return(elementnum);
    }

 count = (elementnum / numelements) * numelements;
 if (count == elementnum)
    {temparray = malloc((count + numelements) * size);

     if (*array)
        {movmem(*array, temparray, count * size);
         free(*array);
        }

    *array = temparray;
    }

 movmem(element, *array+(size*elementnum), size);
 return(elementnum+1);
}

int dosort(char *str1, char *str2)

{return(stricmp(str1, str2));
}
