为了能到远方,脚下的每一步都不能少.|

Dancing-Pierre

园龄:1年10个月粉丝:3关注:0

[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、截图

请添加图片描述

本文作者:Dancing-Pierre

本文链接:https://www.cnblogs.com/wyc-1009/p/17548048.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Dancing-Pierre  阅读(37)  评论(0编辑  收藏  举报  
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起