c – Count edit distance

I have implemented a C code in order to answer an interview question. I would be appreciated if someone would improve the code. Task is an easy, however I want to achieve best efficiency in terms of readability and simplicity. Pardon my English again.

  • Sorry that I have just printed out the result.

The edit distance between two strings refers to the minimum number of
character insertions, deletions, and substitutions required to change
one string to the other. For example, the edit distance between
“kitten” and “sitting” is three: substitute the “k” for “s”,
substitute the “e” for “i”, and append a “g”.

Given two strings, compute the edit distance between them.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned int count_edit_dist(const char list1(),
    const char list2())
    unsigned int count=0;
    size_t len_str1 = strlen(list1);
    size_t len_str2 = strlen(list2);

    for(int i=0; list1(i)!=''; i++)
        if(list2(i)=='') //means len(list2) < len(list1)
            count += (unsigned int)(len_str1 - len_str2);
            return count;

        if(list1(i) != list2(i))

    //reacing here means len(list1) <= len(list2)
    count += (unsigned int)(len_str2 - len_str1);
    return count;

int main(void)
    unsigned int count;
    char list1() = "category";
    char list2() = "caterirrrr";

    count = count_edit_dist(list1, list2);
    printf("edit distance between strings: %un", count);