方法一 :

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 100
void Insert(char *s);

int main()
{
    char str[N];
    printf("Input a string:");
    gets(str);
    Insert(str);
    printf("Insert results:%s\n", str);
    return 0;
}

void Insert(char *s)
{
    char str[N];
    char *t = str;
    strcpy(t, s);
    for (; *t != '\0'; s++, t++)
    {
        *s = *t;
        s++;
        *s = ' ';
    }
    *s = '\0';      /* 在字符串s的末尾添加字符串结束标志 */
}

方法二:

#include <stdio.h>

int main()
{
    char name[100];
    char *p = name;

    printf("请输入你的姓名:");
    scanf("%s", name);

    while (*p != '\0')
    {
        putchar(*p);
        putchar(' ');
        p++;
    }

    return 0;
}


C语言实现在字符串中插入空格
扫码关注作者个人技术公众号,有关技术问题后台回复即可,不定期将有学习资源分享

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-03-10
  • 2021-07-29
  • 2021-12-29
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-12-13
  • 2022-12-23
  • 2021-06-29
相关资源
相似解决方案