单相电表规格:谁能帮我看一道C语言的题啊,谢了!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/20 06:16:03
利用函数和指针编写程序,从键盘输入一个字符串,然后要求输出一个新的字符串.新的字符串在原串中,每两个字符之间插入一个空格,如原串为abcd,新串为
a b c d.
一定要调用函数!

#include <stdio.h>
#include <string.h>

char *transfer(char *in)
{
char *p,*q,*out;
int in_len;
in_len=strlen(in);
out=(char *)malloc(2*in_len*sizeof(char));
p=in;
q=out;
while(p!='\0')
{
*q=*p;
q++;
*q=' ';
q++;
p++;
}
q--;
*q='\0';
return out;
}

void main()
{
char input_char[100],*output_char;
scanf("%s",input_char);
output_char=transfer(input_char);
printf("%s\n",output_char);
}

#include<stdio.h>
#include<STDLIB.H>
void output(char *p)
{
putchar(*p++);
while(*p!='\0')
{
putchar(' ');
putchar(*p++);

}
putchar('.');

}
main()
{
char *ch=(char *) malloc(255*sizeof(char));/*为ch分配空间*/
printf("please input the string\n");
scanf("%s",ch);/*用%s输入字符串,字符末尾会自动加上结束符号'\0'*/
output(ch);
getch();
}