1个回答
2013-12-02
展开全部
#include<iostream>
using namespace std;
void delchar(char* s1, char s2);
int main()
{
char mystring[100];
char mychar;
cout << "input a string(less than 100 chars):";
cin >> mystring;
cout << "input a char:";
cin >> mychar;
cout << "original string: " << mystring << "\n";
delchar(mystring, mychar);
cout << "after delchar: " << mystring << "\n";
return 0;
}
// 算法思想:将删除所s2后的数组先放在一个新的数组中,最后全部复制到原地址
void delchar(char* s1, char s2)
{
char temp[100];
while(*s1 != '0')
{
if(*s1 == s2)
{
s1++;
continue;
}
*temp = *s1;
temp++;
s1++;
}
*temp = '\0';
while( (*s1++ = *temp++) != '\0' );
}
using namespace std;
void delchar(char* s1, char s2);
int main()
{
char mystring[100];
char mychar;
cout << "input a string(less than 100 chars):";
cin >> mystring;
cout << "input a char:";
cin >> mychar;
cout << "original string: " << mystring << "\n";
delchar(mystring, mychar);
cout << "after delchar: " << mystring << "\n";
return 0;
}
// 算法思想:将删除所s2后的数组先放在一个新的数组中,最后全部复制到原地址
void delchar(char* s1, char s2)
{
char temp[100];
while(*s1 != '0')
{
if(*s1 == s2)
{
s1++;
continue;
}
*temp = *s1;
temp++;
s1++;
}
*temp = '\0';
while( (*s1++ = *temp++) != '\0' );
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询