#include <stdio.h> #include <string.h> void pick( const char* s, char* sub, size_t beg, size_t end, size_t step ) { size_t n = strlen(s); end = end<n ? end : n; for( size_t i=beg; i<end; i+=step ) // 这里有个bug --- i+=step 可能溢出,明天再改 *sub++ = s[i]; *sub = '\0'; } int main( void ) { char sub[100]; pick( "Stringhandling", sub, 2, 8, 2 ); puts( sub ); }