这个程序哪出错了,怎么改?

来源:百度知道 编辑:UC知道 时间:2024/05/15 08:02:13
从字符串s1中删去与字符串s2相同的字符.
#include <iostream.h>
#include<string.h>
void delchar(char s1[],char s2[])
{ int k=0,a,b;
char s[80];
a=strlen(s1);
b=strlen(s2);
for(int i=0;i<b;i++)
for(int j=0;j<a;j++)
if(s1[j]!=s2[i]) s[k++]=s1[j];
cout<<s<<endl;
}
void main()
{ char a1[80],a2[80];
cout<<"输入字符串s1:";
cin>>a1[80];
cout<<"输入字符串s2:";
cin>>a2[80];
delchar(a1,a2);
}

这是我写的你看看吧

#include <iostream.h>
#include<string.h>
void delchar(char s1[],char s2[])
{ int k=0,a,b;
char s[80] = {0};
a=strlen(s1);
b=strlen(s2);
bool* bolarray;
bolarray = new bool[a];
for(int z = 0; z < a;z ++)
{
bolarray[z] = false;
}
for(int i = 0;i < b; i ++)
{
for(int j = 0; j < a;j ++)
{

if (s2[i] == s1[j]) {
bolarray[j] = true;
break;
}
}
}
for(int m = 0; m < a; m ++)
{
if (bolarray[m] == false) {
cout << s1[m];
}
}
cout << endl;
delete []bolarray;
}
void main()
{ char a1[80] ={0},a2[80] ={0};
cout<<"输入字符串s1:";
cin>>a1;
cout<<"输入字符串s2:";
cin>>a2;
delchar(a1,a2);
}