一个编程题,急用!!!

来源:百度知道 编辑:UC知道 时间:2024/07/04 08:39:31
、输入一个字符串string,然后在string里面每个字母间加一个空格,请用指针完成。

#include<stdio.h>
#include<CONIO.H>
#include<STDLIB.H>

#define max 100

char * copyString;

void copy(char *,char*);
void insert(char *);

int main()
{
char * string;
string = (char *)malloc(max*sizeof(char));
scanf("%s",string);
insert(string);
printf("%s",string);
getch();
return 0;
}

void copy(char * c,char * s)
{
while(*s!='\0')
{
*c=*s;
s++;
c++;
}
*c='\0';
}

void insert(char * s)
{
copyString = (char*)malloc(2*max*sizeof(char));
copy(copyString,s);
while(*copyString!='\0')
{
*s=*copyString;
s++;
copyString++;
*s=' ';
s++;
}
*s='\0';
}