题目描述
编制函数del_char
函数原型为 void del_char(char *,char),函数的功能是删除a指向的字符串中值为ch的字符,例如从字符串"AscADef"中删除’A’后,字符串为"scDef"。
输入
需要删除的字符ch
需要处理的字符串
输出
处理后的字符串
样例输入
A
AscADef
样例输出
scDef
#include"stdio.h"
#include"string.h"
void del_char(char *s,char c){
int count=0;//字符串含有c的个数
for(int i=0;s[i]!='\0';i++){
s[i-count]=s[i];//后面的往前移动count个
if(s[i]==c)
count++;
}
s[i-count]='\0';
}
int main(){
char s[100]={'\0'};
char ch;
scanf("%c",&ch);
getchar();
gets(s);
del_char(s,ch);
puts(s);
}