http://ideone.com/ArhgnP


char* slice( const char* str, size_t length,

    const size_t offset = 0,

    const size_t copy = 1, const size_t skip = 0,

    size_t remainder = 1 )

{

    if( length <= offset ) return NULL;

    length -= offset;


    remainder               = remainder > 0; 

    const   size_t  pair    = copy + skip;

    const   size_t  pairs   = length / pair * pair;

    remainder               = length % pair * remainder;


    char*           src     = (char*)str + offset;

    char          new_str = (char*)malloc( pairs + remainder );

    const   char*   end     = src + pairs;

    char*           dst     = new_str;


    while( src < end )

    {

        for( size_t i = 0; i < copy; ++i )

            dst[i] = src[i];

        src += pair;

        dst += copy;

    }


    for( size_t i = 0; i < remainder; ++i )

        dst[i] = src[i];

    dst[remainder] = 0;


    return new_str; 

}


왤케 힘들게 짬?