Vladimir Levenshtein’s edit distance algorithm1 as a C library, by Titus. There’s also a CLI: levenshtein(1), and a JavaScript version.
Run:
$ npm i levenshtein.cAnd then include levenshtein.h as follows:
#include "node_modules/levenshtein.c/levenshtein.h"You may also want to include levenshtein.c as follows:
#ifndef __LEVENSHTEIN_C__
#define __LEVENSHTEIN_C__
#include "node_modules/levenshtein.c/levenshtein.c"
#endifThis will include both the function declaration and their definitions into a single file.
#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));
}