int our_strlen( char* str ) { // Straightforward coding style. for ( int i=0; 1; i++ ) { char c = str[i]; if ( c == 0 ) return i; } // Unreachable, but the compiler complains if I don't return something. return 0; } int our_strlen_streamlined( const char* str ) { // Compact coding style. const char *si = str; while ( *si ) si++; return si - str; } #if 0 #include <stdio.h> int main(int argc, char** argv) { for ( int i=1; i<argc; i++ ) { char* const str = argv[i]; int len = our_strlen(str); printf("Input idx %2d Len %2d Val %s\n", i, len, str); } return 0; } #endif