编写自定义函数delete char(char stir.char ch),功能是删除字符串str中的某一个字符ch。

编写自定义函数delete char(char stir.char ch),功能是删除字符串str中的某一个字符ch。在主函数中输入字符串,并输入待删除字符,调用函数  delete_char,实现字符删除,并输出结果字符串。

题解:

void delete_char(char str[], char str2);
int main()
{
	char str[80],ch;
	scanf("%s", &str);
	getchar();
	scanf("%c", &ch);
	delete_char(str, ch);
	printf("%s", str);
	return 0;
}
void delete_char(char str[], char ch)
{
	for (int i = 0; i < 80; i++)
	{
		if (str[i] == ch)
		{
			for (int j = i; j < 80; j++)
			{
			str[j] = str[j + 1];
			}
			i--;
		}
	}
}

 

 

你可能感兴趣的:(C语言,大一新生,开发语言,c语言)