关于C语言的题目!大家帮帮忙啊!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/29 12:46:06
有两个字符串,第一个是已知内容("Good morning"),第二个是空字符串,编写函数change,包括两个参数(*from,*to),实现把from中的内容逆序复制到to中.(运用指针的知识)

#include "stdio.h"
void change(char *from,char *to)
{char *p=from;
int i=0;
while(*(p+1)!='\0')
p=p+1;
while(p>=from)
{*(to+i)=*p;
i++;
p=p-1;
}
i++;
*(to+i)='\0';
i=0;

while(*(to+i)!='\0')
{ printf("%c",*(to+i));
i++;
}
}
main()
{char *from="good morning";
char *p=from;
char *to;
while(*p!='\0')
{printf("%c",*p);
p=p+1;
}
printf("\n");
change(from,to);
}



char *change(char *from,char *to)
{
char *p=to,*q=from;
while(*from!='\0')
*from++;
from--;
while(from!=q-1)
{
*to=*from;
to++;from--;
}
*to='\0';
return p;
}