编写一个函数delchar(char *1,char s2),从字符串s1中删去与s2相同的字符,用main测试该函数。
#include <iostream.h>
void delchar(char *s1,char s2);
void main()
{
char a[80],b;
cout<<"请输入一串字符:";
cin>>a;
cout<<"请输入一个字符:";
cin>>b;
if(a[0]!='\0')delchar(a,b);
cout<<"删减后的字符串为:"<<a<<endl;
}
void delchar(char *s1,char s2)
{
if(*s1!=s2) {s1++;delchar(s1,s2);}
else if(*s1==s2)
{while(*s1!='\0')
{*s1=*++s1;
s1++;
delchar(s1,s2);}
}
}
#include <iostream.h>
void delchar(char *s1,char s2);
void main()
{
char a[80],b;
cout<<"请输入一串字符:";
cin>>a;
cout<<"请输入一个字符:";
cin>>b;
if(a[0]!='\0')delchar(a,b);
cout<<"删减后的字符串为:"<<a<<endl;
}
void delchar(char *s1,char s2)
{
if(*s1!=s2) {s1++;delchar(s1,s2);}
else if(*s1==s2)
{while(*s1!='\0')
{*s1=*++s1;
s1++;
delchar(s1,s2);}
}
}