/* * Program to demonstrate/test user-written string-length function. * (Note that there is a library function strlen that does the same thing, * so this is purely for pedagogical purposes!) */ #include /* count and return number of characters in input */ /* (uses pointer to access individual characters) */ int string_length(char * input) { int count = 0; for (char* p = input; *p != '\0' ; ++p) { ++count; } return count; } /* test/demonstrate string_length function */ void test_string_length(char * input) { printf("length of '%s' is %d\n", input, string_length(input)); } /* main */ int main(void) { test_string_length("hello"); test_string_length("hello world"); return 0; }