`
tower
  • 浏览: 244819 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

chinaunix上的flw写的超级trim

 
阅读更多

#include <stdlib.h>

void trim( char *str )
{
        char *copied, *tail = NULL;

        if ( str == NULL )
                return;

        for( copied = str; *str; str++ )
        {
                if ( *str != ' ' && *str != '\t' )
                {
                        *copied++ = *str;
                         tail = copied;                        
                }
                else
                {
                         if ( tail )
                                 *copied++ = *str;
                }
                printf("%s|%s|%s|\n", str, copied, tail);
        }

        if ( tail )
             *tail = 0;
        else
             *copied = 0;

        return;
}


int main(int argc,char **argv)
{
 trim(argv[1]);
 
 printf("%s\n", argv[1]);
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics