[C语言]使用指针将字符串中的开头连续的 * 号全部移到字符串的尾部

[C语言]使用指针将字符串中的开头连续的 * 号全部移到字符串的尾部

1、题目

编写一个函数,利用指针实现对只包含字母和 * 号的字符串处理。将字符串中的开头连续的 * 号全部移到字符串的尾部

要求使用子函数:char* StrDel(char *s)

示例:

输入:***** st *** ring
输出:st *** ring *****

2、完整代码

#include <stdio.h>
char *StrDel(char* s)
{
	char b[81];
	char* c, * d;
	c = s;
	int i = 0;
	while (*c == '*')
	{
		c++;
	}
	d = c;
	while (*c != '\0')
	{
		b[i] = *c;
		i++;
		c++;
	}
	int e = 0;
	while (s < d)
	{
		b[i] = *s;
		i++;
		s++;
		e++;
	}
	s = s - e;
	for (int j = 0; j < i; j++)
	{
		*s = b[j];
		s++;
	}
	*s = '\0';
}

void main()
{
	char  s[81];  int  n = 0; 
	gets(s);
	StrDel(s);
	puts(s);
}

3、截图

请添加图片描述

posted @ 2022-05-02 15:20  Dancing-Pierre  阅读(47)  评论(0)    收藏  举报  来源