-1

Using the edit distance I have to find how many edits between two strings, which I have already done in my code below, but the part im stuck on is printing the 2d array the output is suppose to look like this: enter image description here

int editdistance(char *s, int ls, char *t, int lt)
{
    int a, b, c;
    if (!ls) return lt;

    if (!lt) return ls;

    if (s[ls] == t[ls])
            return editdistance(s, ls - 1, t, lt - 1);
    a = editdistance(s, ls - 1, t, lt - 1);
    b = editdistance(s, ls,     t, lt - 1);
    c = editdistance(s, ls - 1, t, lt    );

    if (a > b) a = b;
    if (a > c) a = c;

    return a + 1;
}

int main()
{
char s1[100];
char s2[100];
printf("first: \n");
scanf("%s",s1);
printf("second: \n");
scanf("%s",s2);

printf("edit distance: %d\n", editdistance(s1, strlen(s1), s2, strlen(s2)));

    return 0;
}
TheOne817
  • 37
  • 6

1 Answers1

0

If i am right, you are looking for Levenshtein distance. this is an algorithm in Dynamic programming.

yd1
  • 277
  • 4
  • 13
  • so what is the problem? translation to C? (because there is code in Wikipedia you can simply copy) – yd1 Nov 06 '16 at 07:49