#include <stdio.h>
#include <stdlib.h>
/****Copyright (c) 1997,1998,1999-2002 All rights reserved
 ****A. V. Gerbessiotis 
 ****Permission to use, copy, modify, and distribute this software,
 ****and to incorporate it, in whole or in part, into 
 ****other software,is hereby granted without fee, provided that
 ****  (1) the above copyright notice and this permission 
 ****      notice appear in all copies of the source code, and 
 ****      the above copyright notice appear in clearly visible 
 ****      form on all supporting documentation and distribution 
 ****      media, and
 ****     (2) any redistribution of the software, in original
 ****         or modified form, be without fee and subject to
 ****         these same conditions.
 ****   No guarantee, whatsoever, is offered that the code works as
 ****   advertised or is absent of any, even damaging,
 ****   side-effects. Use this code at your own personal risk.
 ****/


void str_select(char *keys, int n, int size, int (*compare) ())
{
	register int i,j,k;
	char	*x;

	x = (char *) malloc(size*sizeof(char));
	for(i=0;i<n-1;i++)
	{
		k=i;
		memcpy(x,&keys[i*size],size);
		for(j=i+1;j<n;j++)
		{
			if (compare(&keys[j*size],x) < 0)
			{
				k=j;
				memcpy(x,&keys[j*size],size);
			}
		}
		memcpy(&keys[k*size],&keys[i*size],size);
		memcpy(&keys[i*size],x,size);
	}
}
