Add another test and docs

This commit is contained in:
Christine Dodrill 2015-06-19 15:38:00 -07:00
parent 0663f56757
commit a06304f577
1 changed files with 12 additions and 1 deletions

View File

@ -2,6 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// string_compare_guy compares the contents of the left hand side, length with the contents of the
// right hand side, length and returns 1 if the right hand side (needle) is inside the left hand
// side (haystack).
static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) { static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) {
char* lnz = malloc(llength + 1); char* lnz = malloc(llength + 1);
memcpy(lnz, lhs, llength); memcpy(lnz, lhs, llength);
@ -30,7 +33,7 @@ int main() {
printf("passed\n"); printf("passed\n");
} }
printf("trying to find foo in foobar\n"); printf("trying to find foobar in foo\n");
if(string_compare_guy("foo", 3, "foobar", 6)) { if(string_compare_guy("foo", 3, "foobar", 6)) {
retcode++; retcode++;
printf("failure\n"); printf("failure\n");
@ -38,5 +41,13 @@ int main() {
printf("passed\n"); printf("passed\n");
} }
printf("trying to find foo in foobar\n");
if(string_compare_guy("foobar", 3, "foo", 6)) {
printf("passed\n");
} else {
retcode++;
printf("failure\n");
}
return retcode; return retcode;
} }