用字符数组作函数参数编程实现在字符串每个字符间插入一个空格的功能。
**输入提示信息:"Input a string:"
**输入格式要求:"%s"
**输出格式要求:"\nInsert result:%s\n"
程序运行示例1如下:
Input a string:Howareyou
Insert result:H o w a r e y o u
#include <stdio.h>
#include <string.h>
#define N 100
void Insert(char s[]);
main()
{
char str[N];
printf("Input a string:");
gets(str);
Insert(str);
printf("\nInsert result:%s\n", str);
}
void Insert(char s[])
{
char t[N];
int i, j;
strcpy(t, s);
for (i = 0, j = 0; t[i] != '\0'; i++, j++)
{
s[j] = t[i];
j++;
s[j] = ' ';
}
s[j] = '\0'; /* 在字符串s的末尾添加字符串结束标志 */
}