只能输入字符,将字母前面的*转移到字符串的结尾

cs 复制代码
#include <stdio.h>
void  fun(char* a)
{
    int m = 0, i = 0;
    char* p;
    p = a;
    while (*p == '*')
    {
        m++;
        p++;
    }
    while (*p != '\0')
    {
        a[i++] = *p;
        p++;
    }
    while (m != 0)
    {
        a[i++] = '*';
        m--;
    }
    a[i] = '\0';
}

void main()
{
    char  s[81];  int  n = 0;
    printf("Enter a string:\n"); gets(s);
    fun(s);
    printf("The string after moveing:\n"); puts(s);
}

输出结果:

相关推荐
iuu_star19 小时前
C语言数据结构-顺序查找、折半查找
c语言·数据结构·算法
JoyCheung-1 天前
Free底层是怎么释放内存的
linux·c语言
阿华hhh1 天前
项目(购物商城)
linux·服务器·c语言·c++
方便面不加香菜1 天前
基于顺序表实现通讯录项目
c语言·数据结构
无限进步_1 天前
【数据结构&C语言】对称二叉树的递归之美:镜像世界的探索
c语言·开发语言·数据结构·c++·算法·github·visual studio
Eternity∞1 天前
基于Linux系统vim编译器情况下的C语言学习
linux·c语言·开发语言·学习·vim
HUST1 天前
C语言第十一讲: 深入理解指针(1)
c语言·开发语言
SoveTingღ1 天前
【C语言】什么是野指针?
c语言·指针·嵌入式软件
lowhot1 天前
C语言UI框架
c语言·开发语言·笔记·ui