next up previous contents index Search
Next: 0.5.10.2 References Up: 0.5.10 Soundex English word-sounding Previous: 0.5.10 Soundex English word-sounding

0.5.10.1 Source Code

#include <ctype.h>
#include <string.h>

int soundex (char *input, char *output) {

  char values[] =

    /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
     ``01230120022455012623010202'';


  int done;
  char this_char, prev_char, replace_char;
  char code[5];


  strcpy(code, ``     '');
  if (isalpha(this_char = toupper(*input))) {
    code[0] = this_char;
    done = 1;
    input++;
  } else return(0);
  prev_char = ' ';

  while (done < 4 && isalpha(*input)) {
    this_char = toupper(*input);
    replace_char = values[this_char = 'A'];

    if ((replace_char != prev_char) && (replace_char != '0')) {
      prev_char = code[done++] = replace_char;
    }
    input++;
  }


  if ((*input != '\0') && (!isalpha(*input))) {
    return(0);
  } else {
    strcpy (output, code);
    return(1);
  }
}

Scott Gasch
1999-07-09