C language programming> 22nd week ⑥ Please add the fun function. The function of this function is to delete the characters whose subscripts can be divisible by 2 and 3 from the string s, and save the remaining characters in the string again s.

Example: Please add the fun function. The function of this function is to delete the characters whose subscripts can be divisible by 2 and 3 from the string s, and save the remaining characters in the string s again. The string s is input from the keyboard, and its length is passed into the fun function as a parameter.

例如,输入 “abcdefghijk”,则输出 “bcdefhijk”。
请勿改动主函数main与其它函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。

代码如下:

#include<stdio.h>
#define N 100
void fun(char p[],int n)
{
    
    
	int i,k;
	k=0;
	for(i=0;i<n;i++)
	{
    
    
		p[k++]=p[i];
		if((i%2==0)&&(i%3==0))
			k--;
	}
	p[k]='\0';
}
main()
{
    
    
	int i=0,strlen=0;
	char s[N];
	printf("Please input a string:\n");
	gets(s);
	while(s[i]!='\0')
	{
    
    
		strlen++;
		i++;
	}
	fun(s,strlen);
	printf("The new string:\n");
	puts(s);
}

The output running window is as follows:
Insert picture description here

越努力越幸运!
加油,奥力给!!!

Guess you like

Origin blog.csdn.net/qq_45385706/article/details/112801789