字符串替换

#include "stdafx.h" <iostream>

char

{

int lens=strlen(s);

int lent =strlen(t);

int n=0;//n means how many

 

char *string = new char[100];//the last is'/0'

int q=0;

for(int i = 0;i<lens;i++)

{

if (s[i]!=c)

{

string[q++]=s[i];

}

else

{

for(int j=0;j<lent;j++)

string[q++]= t[j];

}

continue;

 

 

}

string[q]='/0';

return string;

}

int

{

char *s = tiHuan("abcbc","fg",'b');

printf("%s/n",s);

system("pause");

return 0;

}

**************************************************************************************

下面补充正面代码:

 

// TiHuan.cpp : Defines the entry point for the console application.

//

#include

"stdafx.h"

#include

<iostream>

char

{

int lens=strlen(s);

int lent =strlen(t);

 

 

char *string = new char[100];//the last is'/0'

 

for(int i=0;i<lens;i++)

{

string[i]=s[i];

}

int x = 0;//ji shu

int l;//zui hou yi wei

/*int q=0;*/

for(int i = 0;i<lens;i++)

{

if (s[i]==c)

{

int tempInt=0;//

char *temp = new char[lens];//zui duo lens ge

int h=i+x*lent-x;

//baoCun

for(int k=i+1;k<lens;k++)//k=i+1,not h+1

{

temp[tempInt++]=s[k];//s,not string

}

//tiHuan

 

for(int j=0;j<lent;j++)

{

string[h++]=t[j];

}

//buCong

for(int g=0;g<tempInt;g++)

{

string[h++]=temp[g];

 

}

x++;

l=h;

//string[q++]=s[i];

}

/*else

continue;

 

 

}

string[l]='/0';

return string;

}

int

{

char *s = tiHuan("abcbcjk","fg",'b');

printf("%s/n",s);

system("pause");

return 0;

}

_tmain(int argc, _TCHAR* argv[])

{

for(int j=0;j<lent;j++)

string[q++]= t[j];

}*/

* tiHuan(char*s,char *t,char c)

 

#include

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值