第七周作业--预习

这个作业属于那个课程 C语言程序设计II
这个作业要求在哪里 要求
我在这个课程的目标是 运用指针函数
这个作业在哪个具体方面帮助我实现目标 指针的使用
参考文献 数组与指针

使用函数删除字符串中的字符

输入一个正整数 repeat (0<repeat<10),做 repeat 次下列运算:

输入一个字符串 str,再输入一个字符 c,将字符串 str 中出现的所有字符 c 删除。
要求定义并调用函数delchar(str,c), 它的功能是将字符串 str 中出现的所有 c 字符删除,函数形参str的类型是字符指针,形参c的类型是char,函数类型是void。

输入输出示例:括号内为说明,无需输入输出

输入样例:

3               (repeat=3)
happy new year  (字符串"happy new year")
a               (待删除的字符'a')
bee             (字符串"bee")
e               (待删除的字符'e')
111211          (字符串"111211")
1               (待删除的字符'1')

输出样例:

result: hppy new yer    (字符串"happy new year"中的字符'a'都被删除)
result: b               (字符串"bee"中的字符'e'都被删除)
result: 2               (字符串"111211"中的字符'1'都被删除)

代码:

#include <stdio.h>
void fun(char str[],char c);
int main(void)
{
	int repeat;
	char str[100],c;
	
	scanf("%d
", &repeat);

	while(repeat--)
	{
		gets(str);
		
		scanf("%c", &c);	
		
		printf("result: ");
		
		fun(str,c);
	}
	
	return 0;
}
void fun(char str[],char c)
{
 	while(*str != '')
	{
		if(*str != c)
		{
			putchar(*str);
        }
        str++;
   }
}

流程图:

原文地址:https://www.cnblogs.com/zw431387/p/10695463.html