求高手解答一下C语言题

2025-01-08 12:15:57
推荐回答(2个)
回答1:

#include
#include
#define N 100
void main()
{
char a[N],b[N],c[N];
int n,m,i,j;
printf("please in put a string:");
gets(a);
printf("please in put another:");
gets(b);
printf("please in put another:");
gets(c);
n=strlen(c);
m=strlen(b);
for(j=0;j<=N;j++)
{
if(a[j]==b[0])
break;

}
printf("%d",n);
for(i=0;i a[i+j]=c[i];
for(i=n;i a[i+j]=' ';
puts(a);

}
输入顺序为you want someone help you
you
I
上面的程序满足你的要求,但我必须说明它是有漏洞的,如果有其他要求我可以无偿帮你改进他。

回答2:

#include
#include
#include
int main()
{
char *input,*pre,*output,*post,*p;
input=(char*)malloc(100*sizeof(char));
pre=(char*)malloc(100*sizeof(char));
post=(char*)malloc(100*sizeof(char));
output=(char*)malloc(100*sizeof(char));
memset(output,0,100*sizeof(char));
cin.getline(input,100,'\n');
cin.getline(pre,100,'\n');
cin.getline(post,100,'\n');
p=strstr(input,pre);
if(p==NULL)
{
strcpy(output,input);
return 1;
}
while(p)
{
strncat(output,input,p-input);
strcat(output,post);
p+=strlen(pre);
input=p;
p=strstr(p,pre);
}
strcat(output,input);
cout< return 0;
}