Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1749539
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类: C/C++

2010-10-19 17:08:34

void replace_string(char * source_str,char * targ_str,char *val)
{
        char temp_sstr[4096],result[4096];
        char * p,*q;
        int len;
        len=0;
        q=p=NULL;
        memset(result,0,sizeof(result));
        memset(temp_sstr,0,sizeof(temp_sstr));
        strcpy(temp_sstr,source_str);
        p=q=temp_sstr;
        len=strlen(targ_str);
        while(q!=NULL)
        {
                if((q=strstr(p,targ_str))!=NULL)
                {
                        strncat(result,p,q-p);
                        strcat(result,val);
                        strcat(result,"\0");
                        q+=len;
                }
                else
                        strcat(result,p);
        }
        strcpy(source_str,result);
}
阅读(714) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~