/* strcmpn.c - string compare between a string and a number of characters */ /* PUBLIC DOMAIN - Jon Mayo - October 11, 2006 */ /*! * description: compares a with b[0..b_len]. * parameters: * a - the first string, must be null terminated * b - second string. no null termination (series of characters) * b_len - length of b. * returns: * negative if a #include static void test(const char *a, const char *b, unsigned b_len) { int r; r=strcmpn(a, b, b_len); printf("\"%s\" %c \"%.*s\"\n", a, r<0?'<':r>0?'>':'=', b_len, b); } int main(int argc, char **argv) { int i; if(argc<2) { /* default test */ test("Hello", "Worldasdfkadsf", 5); test("Hello", "World", 5); test("Hello", "World", 1); test("Hello", "Hello", 5); test("Hello", "Helloaskdjfkadsf", 5); test("World", "World", 5); test("Hello", "Hello", 1); test("World", "Hello", 5); test("Hello", "Hello", 0); } /* compares the first parameter with all the other parameters */ for(i=2;i