From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX"  7-JUL-1992 15:40:06.71
To:	info-vax@kl.sri.com
CC:	
Subj:	RE: Soundex Algorithm

Dear all,

Here is a soundex algorithm such as it is. As you can see from the header 
it is quite old. I don't think that it that good mind you ( to my recollection
words will only have the same soundex if they start with the same letter  ....
eg cat and kat would be different). If anyone's got anything better (not
necessarily soundex) I'd be interested.


           Declan


 +-----------------+-----------------------+
 [ Declan Higgins /                        ]
 [               / dhiggins@bfsec.bt.co.uk ]
 +--------------+--------------------------+





Cut along the dashed line ....

--------------------------------------------------------------------------------
/****************************************************************
*	SOUNDEX ALGORITHM in C					*
*			 					*
*	The basic Algorithm source is taken from EDN Nov.	*
*	14, 1985 pg. 36.					*
*								*
*	As a test Those in Illinois will find that the		*
*	first group of numbers in their drivers license		*
*	number is the soundex number for their last name.	*
*								*
*	RHW  PC-IBBS ID. #1230					*
*								*
****************************************************************/

#include <ctype.h>
char (*soundex(out_pntr, in_pntr))
char *in_pntr;
char *out_pntr;
{
extern char get_scode();
char ch,last_ch;
int count = 0;

	strcpy(out_pntr,"0000");	/* Pre-fill output string for    */
					/* error and trailing zeros.     */
	*out_pntr = toupper(*in_pntr); 	/* Copy first letter             */
	last_ch = get_scode(*in_pntr);	/* code of the first letter      */
					/* for the first 'double-letter  */
					/* check.			 */
					/* Loop on input letters until   */
					/* end of input (null) or output */
					/* letter code count = 3	 */

	while( (ch = get_scode(*(++in_pntr)) ) && (count < 3) )
	{
	if( (ch != '0') && (ch != last_ch) ) /* if not skipped or double */
		*(out_pntr+(++count)) = ch; /* letter, copy to output */
		last_ch = ch;	/* save code of last input letter for */
				/* next double-letter check */
	}
	return(out_pntr);	/* pointer to input string */
}

char get_scode(ch)
char ch;
{
			    /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
		            /* :::::::::::::::::::::::::: */
static char soundex_map[] =   "01230120022455012623010202";

	/* If alpha, map input letter to soundex code. If not, return 0 */

	if( ! isalpha(ch) )	/*error if not alpha */
		return(0);
	else
		return(soundex_map[(toupper(ch) - 'A')] );
}

main(argc, argv)
int	argc;
char	*argv[];
{
char	*code[10];

int	i;

	if(argc == 1) /* No arguments, give usage */
	{
	printf("\nUsage: soundex (name) (...)\n");
	exit(1);
	}

	for(i = 1; i < argc; i++)
	{
	soundex(code, argv[i]) ;
	printf("The Soundex Code for \"%s\" is: %s\n", argv[i],code);
	}
	exit(0);
}

