Vladimir Levenshtein’s edit distance algorithm1 as a C library. There’s also a CLI: levenshtein(1), and a JavaScript version.
CLib:
$ clib install wooorm/levenshtein.c
Or clone the repo.
#include <stdio.h>
#include "levenshtein.h"
int
main(int argc, char **argv) {
char *a = argv[1];
char *b = argv[2];
if (argc < 3) {
fprintf(stderr, "\033[31mLevenshtein expects two arguments\033[0m\n");
return 1;
}
printf("%zu\n", levenshtein(a, b));
}
#include <stdio.h>
#include "levenshtein.h"
int
main() {
const char *a = "foobar";
const char *b = "hello";
printf("%zu\n", levenshtein_n(a, 6, b, 5));
}