-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdmtest.cc
33 lines (29 loc) · 807 Bytes
/
dmtest.cc
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
#include <vector>
#include <string>
#include "double_metaphone.h"
#include "stdio.h"
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char line[512];
char *word;
if (argc != 2) {
printf ("Usage: dmtest <filename>\n"
" where <filename> contains one word per line, will print\n"
" each word with its 2 double metaphone values.\n");
exit(1);
}
FILE* f = fopen(argv[1], "r");
while (!feof(f)) {
word = fgets(line, sizeof(line), f);
if (word && strlen(word)) {
vector<string> codes;
if (word[strlen(word) - 1] == '\n') {
word[strlen(word) - 1] = '\0';
}
string s = string(word);
DoubleMetaphone(s, &codes);
printf ("%s,%s,%s\n", word, codes[0].c_str(), codes[1].c_str());
}
}
}