编程从键盘输入一个字符串和一个指定字符, 删除该字符串中所有指定的字符,将结果保存到一个新的字符串中并输出

在这里插入图片描述

/*编程从键盘输入一个字符串和一个指定字符,
删除该字符串中所有指定的字符,将结果保存到一个新的字符串中并输出*/
#include<stdio.h>
#include<string.h>
 main()
{	char str[100],s[100],c;
	int i=0,j=0;
	printf("请输入一个字符串:"); 
	gets(str);
	printf("请输入指定的字符:"); 
	c=getchar();
	while(str[i]!='\0')
	{	if(str[i]!=c)/*判断是否为指定的字符*/
		{	s[j]=str[i];
			j++; 
		}
			i++;
	}
	s[j]='\0';
	puts(s);	 
}

猜你喜欢

转载自blog.csdn.net/YJG7D314/article/details/89056218
今日推荐