#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