Classic delete the specified character in the string

The key to this question is to understand the for statement and when the IF statement ends.

for (i=j=0;str[i]!='\0',i++)

if(str[i]!='c')

s[j++]=s[i];

s[j]=0;

 

#include <stdio.h>
void  fun(char  *s)
{
 int  i, j;
 for (i=j = 0; s[i] != '\0'; i++)
  if (s[i] != 'c')
   /************found************/
   s[j++] = s[i];
   s[j] = 0;
 /************found************/
 
}
void main()
{
 char  s[80];
 printf("enter a string:       "); gets(s);
 printf("the original string:  "); puts(s);
 fun(s);
 printf("the string after deleted :  "); puts(s); printf("\n\n");
}

 

 

 

Guess you like

Origin www.cnblogs.com/pquan/p/12745882.html