C编程实现删除字符串中所有指定的字符

void deleteChar(char* str, char deChar)
{
	char* p = NULL;
	if (str == NULL) return;

	p = str;

	while (*p)
	{
		if (*p != deChar)
		{
			*str++ = *p;
		}
		p++;
	}

	*str = '\0';
}



int main()
{
	char num[] = "54678";
	char deChar = '4';

	deleteChar(num, deChar);
	cout << num << endl;

	system("pause");
	return 0;
}
发布了55 篇原创文章 · 获赞 1 · 访问量 3773

猜你喜欢

转载自blog.csdn.net/lpl312905509/article/details/104087758
今日推荐