任务描述
本关任务:规定输入的字符串中只包含字母和*
号。给定程序的功能是将字符串中的前导*
号全部移到字符串的尾部。请将程序补充完整,使其能正确运行得出结果。
相关知识
相关知识略
编程要求
请仔细阅读右侧代码,结合相关知识,在右边提示区域内进行代码补充,完成编写星号转移的小程序。
测试说明
平台会对你编写的代码进行测试:
测试输入: ***abcd
预期输出: abcd***
#include "stdio.h"
#define N 19
void fun(char*p);
int main()
{
char s[N];
gets(s);
fun(s);
puts(s);
return 0;
}
void fun(char*a)
{
int cnt_star = 0,i = 0;
char *p = a;
while( *p =='*')
{
cnt_star ++;
p ++;
}
while( *p != '\0')
{
a[i] = *p;
i++,p++;
}
while(cnt_star != 0)
{
a[i] = '*';
i++;
cnt_star --;
}
a[i] = '\0';
}