经典的删除字符串中指定的字符

这道题的关键在于理解for 语句以及IF语句何时结束。

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");
}

猜你喜欢

转载自www.cnblogs.com/pquan/p/12745882.html