-
Notifications
You must be signed in to change notification settings - Fork 0
/
soundex.c
51 lines (43 loc) · 1.03 KB
/
soundex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "soundex.h"
//--------------------------------------------------------
// FUNCTION soundex
//--------------------------------------------------------
void soundex(char *name, char *s)
{
int si = 1;
char c;
// ABCDEFGHIJKLMNOPQRSTUVWXYZ
char mappings[] = "01230120022455012623010202";
s[0] = toupper(name[0]);
for (int i = 1, l = strlen(name); i < l; i++)
{
c = toupper(name[i]) - 65;
if (c >= 0 && c <= 25)
{
if (mappings[c] != '0')
{
if (mappings[c] != s[si - 1])
{
s[si] = mappings[c];
si++;
}
if (si > 3)
{
break;
}
}
}
}
if (si <= 3)
{
while (si <= 3)
{
s[si] = '0';
si++;
}
}
}