假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:将字符串中的前导*号全部移到字符串的尾部

/假定输入的字符串中只包含字母和号。请编写函数fun,它的功能是:将字符串中的前导*号全部移到字符串的尾部。 */

#include <stdio.h>
#include <string.h>
void fun(char *str)
{
    int i=0,count=0;
    int len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(str[i]=='*')
        {
            count++;
        }
    }
    for(i=0;i<len-count;i++)
    {
        str[i]=str[i+count];
    }
    for(i=0;i<count;i++)
    {
        str[len-count+i]='*';
    }
}
int main()
{
    char str[100];
    int n = 2;
    printf("please input letter an *\n");
    scanf("%s",str);
    fun(str);
    printf("%s\n", str);
    return 0;
}

posted on 2024-06-24 23:56  wessf  阅读(49)  评论(0)    收藏  举报