Skip to content

Instantly share code, notes, and snippets.

@soarez
Created Aug 16, 2012
Embed
What would you like to do?
word_diff
int partial_match(char *word_a, char *word_b, int len) {
int res, idx;
res = 0;
for(idx = 0; idx < len; ++idx)
if (word_a[idx] == word_b[idx])
++res;
return res;
}
int word_diff(char *word_a, char *word_b) {
char *small, *big;
int len_a, len_b, small_len, big_len, diff;
int idx, match, biggest_match;
len_a = strlen(word_a);
len_b = strlen(word_b);
if (len_a > len_b) {
big = word_a;
small = word_b;
big_len = len_a;
small_len = len_b;
} else {
big = word_b;
small = word_a;
big_len = len_b;
small_len = len_a;
}
biggest_match = 0;
diff = big_len - small_len;
for(idx = 0; idx <= diff; ++idx) {
match = partial_match(small, big + idx, big_len - idx);
if (match > biggest_match)
biggest_match = match;
}
return big_len - biggest_match;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment