按分隔符取串中的项
char *
item_get_by_dlmt( char * str, char * delimit, int * pos )
{
char * p;
char * item;
int item_len;
if ( str == NULL || delimit == NULL || pos == NULL )
return ( NULL );
if ( * pos == strlen( str ) )
return ( NULL );
p = strstr( (str+*pos), delimit );
if ( p != NULL )
{
item_len = p - &str[*pos];
item = calloc( 1, item_len + 1 );
memcpy( item, &str[ * pos ], item_len );
* pos = * pos + item_len + strlen( delimit );
}
else if ( strlen( &str[*pos] ) > 0 )
{
item_len = strlen( &str[*pos] );
item = calloc( 1, item_len + 1 );
memcpy( item, &str[ * pos ], item_len );
* pos = * pos + item_len;
}
else
return ( NULL );
return ( item );
}
阅读(743) | 评论(0) | 转发(0) |