#include #include #include static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) { char* lnz = malloc(llength + 1); memcpy(lnz, lhs, llength); lnz[llength] = 0; char* rnz = malloc(rlength + 1); memcpy(rnz, rhs, rlength); rnz[rlength] = 0; int result = strstr(lnz, rhs); free(lnz); free(rnz); return result; } int main() { int retcode = 0; printf("Comparing foo and bar\n"); if(string_compare_guy("foo", 3, "bar", 3)) { retcode++; printf("failure\n"); } else { printf("passed\n"); } printf("trying to find foo in foobar\n"); if(string_compare_guy("foo", 3, "foobar", 6)) { retcode++; printf("failure\n"); } else { printf("passed\n"); } return retcode; }