C removes a specific character from a character array
- 2020-04-02 03:09:23
- OfStack
Delete a specific character from the character array, that is, input to delete the specified character, using the for loop to find the non-specified character, the non-specified character can be output. The following is the specific implementation method:
#include<stdio.h>
int main()
{
char str[100],c;
int j,k;
printf("please input a string:");
gets(str);
printf("nEnter a character:");
c=getchar();
for(j=k=0;str[j]!='0';j++)
if(str[j]!=c)
str[k++]=str[j];
str[k]='0';
printf("n%s",str);
}
<pre name="code" class="cpp">please input a string:wqeqwe
Enter a character:w
qeqePress any key to continue
Through the concrete implementation method, I hope to be helpful to you.