// testing fgets and my_strlen // #include #include // stdin, stdout, stderr // printf( "fmt", ...) same as: fprintf( stdout, "fmt", ...) // scanf( "fmt", ...) same as: fscanf( stdin, "fmt", ...) #define SIZE 8096 // size of the line char array size_t my_strlen( const char s[]) { // size_t len = 0; while( s[len] != 0) ++len; // using array indexing // size_t len = 0; while( *s != 0) { ++len; ++s; } // using pointer and counter // return len; const char *save = s; while( *s != 0) ++s; // using just pointers return s-save; } int main( void) { char line[SIZE]; while( fgets( line, SIZE, stdin) ) { char *p = strchr( line, '\n'); if( p != 0) *p = 0; // kill newline printf( "%zi: ", my_strlen(line) ); printf( "%s\n", line); // fputs( line, stdout); } return 0; }