这段代码能输出结果, 但是总觉得有问题, 高手指教
#include "string.h "
#include "stdio.h "
#include "malloc.h "
main(void)
{
char *src= "hello,world ";
char *dest=NULL;
int len;
char *d;
char *s;
dest=(char *)malloc(sizeof(char)*(strlen(src)+1));
len=strlen(src);
d=dest;
s=src+len-1;
while(len--!=0)
*d++=*s--;
*d= '\0 ';
printf( "%s ",dest);
}
[解决办法]
逻辑上没有错误
代码可以优化一下
一些赋值可以写成初始化,strlen两次没必要,用len