字符串中字符的删除

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 char *fun(char *s,char c)
 5 {
 6       char *p=s;   //用指针p指向字符串s的首地址
 7       char *pp=p;  //pp指向字符串p的首地址
 8       for(;*s != '\0';s++)    //如果指向的当前字符串不是‘\0’
 9       {
10               if(*s != c)       //如果当前字符串不等于指定字符
11               {
12                    *p++ = *s;     //将当前字符写入指针p
13                  }
14        }
15        *p = '\0’      //字符串末尾增加字符串结束标志16        return pp;     //返回所得字符串
17 }
18 
19 int main()
20 {
21     char s[20] = "Hello world!";
22     printf("%s\n",s);
23     char *ppr;
24     ppr=fun(s,'l');
25     printf("%s\n",ppr);
26     return 0;
27 }
posted @ 2015-07-03 20:45  Vmetrio  阅读(1141)  评论(0编辑  收藏  举报