/* * Program to demo/test two string-length functions (solely to * illustrate working with strings, since there is a library * function strlen). */ #include /* compute string length, operating on string as array */ int lng1(char s[]) { int lng = 0; while (s[lng] != '\0') ++lng; return lng; } /* compute string length, operating on string using pointer */ int lng2(char *s) { char *p = s; while (*p != '\0') ++p; return p-s; } /* main */ int main(void) { char *input = "hello world"; printf("lng1 of %s = %d\n", input, lng1(input)); printf("lng2 of %s = %d\n", input, lng2(input)); return 0; }