从键盘数入一个字符串,要求在输入的字符串中每两个字符之间插入一个空格,如:原串aabbcc,要求输入的新串为a a b b c c。此题要求用函数调用实现,且要求用指针变量作形参。
#include<stdio.h>#include<ctype.h>voidInsert(char *p){int i;/*结束为止应该在1位置,下标从0开始*/for (i = strlen(p); i > 0; --i){*(p + 2 * i) = *(p + i);*(p + 2 * i - 1) = ' ';}}int main(){char s[100];printf("Please input s:");gets_s(s, 100);Insert(s);printf("the new string:%s", s);return 0;}本程序在VS2017下运行通过