输入字符串和字符,去掉字符串中所有该字符

题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入:

    测试数据有多组,每组输入字符串s和字符c。

输出:

    对于每组输入,输出去除c字符后的结果。

样例输入:

    heallo

    a

样例输出:

    hello

下面请看程序:

#include<stdio.h>
#include<string.h>

int main()
{
	char c;
	char str[100];
	printf("input a word: ");
	while(scanf("%s",&str)!='\n')
	{
		getchar();
		printf("delete: ");
		scanf("%c",&c);
		for(int i=0;i<strlen(str);i++)
		{
			if(str[i]==c) continue;        // 如果指到我们不想要的字母,直接continue跳出本次循环
			else printf("%c",str[i]);
		}	
	}
	return 0; 
}


程序运行截图:


猜你喜欢

转载自blog.csdn.net/weixin_41656968/article/details/80193390
今日推荐