/** * Recursive implementation of strcmp * @author gtowell * Created: Match 2021 * **/ #include /** * Recursive implementation of strcmp. Strongly assumes that at least one of the passed * params is null terminated * @param stri -- the first string to be compared * @param str2 -- the second string to be compared * @return true if the strings are the same length and character-wise identical * **/ int strcmprec(char * str1, char * str2) { if (*str1 == '\0') { return *str1 == *str2; } if (*str2 == '\0') { return 0; } if (*str1 != *str2) { return 0; } return strcmprec(++str1, ++str2); } /** * Compares the first two command line args for similarity * **/ int main(int argc, char const *argv[]) { printf("%s %s %s\n", argv[1], argv[2], strcmprec((char *)argv[1], (char *)argv[2]) ? "MATCH" : "DO NOT match"); return 0; }