workshit/src/string_compare_guy.c

43 lines
750 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}