C语言通过指针删除字符串指定的字符

直接看代码

#include 
#include 
void fun( char s[],char c)
{
     	printf("fun函数的字符串%s",s);
  //数组s删除指定字符
   char *p;
   for(p=s;*p!='\0';p++)
   	{
     if(*p!=c)
   			*s++=*p;
		   }	
	*s='\0';//字符串结束标志 
	
}
int main(){
     
	char str[]="turbo c and borland c++";
  	char ch;
  	printf ("原始字符串:%s\n",str);
	printf("输入一个字符:");
	scanf("%c",&ch);
	fun(str,ch);
	printf("str[]=%s\n",str);
		return 0;
}

你可能感兴趣的:(C与C++)