Chinaunix首页 | 论坛 | 博客
  • 博客访问: 612488
  • 博文数量: 144
  • 博客积分: 5037
  • 博客等级: 大校
  • 技术积分: 1581
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-30 21:49
文章存档

2010年(16)

2009年(128)

分类: LINUX

2009-08-06 13:52:47

//replace.c

char *my_replace(char *str_parent, char *str_old, char *str_new)
{
    char *tmp_str[1024];
    char tmp_buf[4096] = {""};
    int i = 0;
    int size = 0;

    tmp_str[i] = strtok(str_parent, str_old);
    if(tmp_str[0] != NULL)
    {
        while((tmp_str[++i] = strtok(NULL, str_old)));
    }
    tmp_str[i] = NULL;
    size = i;
    
//    if(strncmp(tmp_buf, str_old, strlen(str_old) - 1) == 0)
//    {
//        strcat(str_parent, str_new);
//    }

    for(i = 0; i < size; i++)
    {
        strcat(tmp_buf, tmp_str[i]);
        strcat(tmp_buf, str_new);
    }
    strcpy(str_parent, tmp_buf);        //bak

    return str_parent;
}

//mian函数自己随便写个测试就可以了。

阅读(683) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~