新手请前辈改程序
各位前辈大家好!我是C语言新手
要编写程序完成字符串替换
字符串、被替换词、替换后的词均由键盘读入
编译出很多错误
有些说明看不懂
请前辈指教
多谢
#include<conio.h>
#include<stdio.h>
#define MAX 100
char string[MAX];
char old[MAX];
char newly[MAX];
void replace()
{
int i=0,j=0,k,l,start,len_old=0,len_newly=0,len_string=0;
while(old[len_old]!="\n")
len_old++;
len_old-=1;
while(newly[len_newly]!="\n")
len_newly++;
len_newly-=1;
while(string[len_string]!="\n")
len_string++;
len_string-=1;
for(i=0;i<MAX;)
{
if( for (j=i;j<i+len_old;j++) string[j]==old[j-i] )
start=i;
for(k=start+len_newly-1;k<MAX;k++)
string[k]=string[k+len_newly-len_old];
for(l=start;l<start+len_newly;l++)
string[l]=newly[l-start];
i=start+len_newly;
}
}
int main()
{
printf("please input a string(no more than 100 letters)\n");
gets(string);
printf("please input the word to be replaced\n");
gets(old);
printf("please input the word to replace the old one\n");
gets(newly);
replace(string,old,newly);
printf("%s",string);
getch();
}