您的位置:首页 > 其它

字符串中字符的删除

2015-07-03 20:45 417 查看


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *fun(char *s,char c)
{
char *p=s;   //用指针p指向字符串s的首地址
char *pp=p;  //pp指向字符串p的首地址
for(;*s != '\0';s++)    //如果指向的当前字符串不是‘\0’
{
if(*s != c)       //如果当前字符串不等于指定字符
{
*p++ = *s;     //将当前字符写入指针p
}
}
*p = '\0’      //字符串末尾增加字符串结束标志        return pp;     //返回所得字符串
}

int main()
{
char s[20] = "Hello world!";
printf("%s\n",s);
char *ppr;
ppr=fun(s,'l');
printf("%s\n",ppr);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: