首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

这段代码能输出结果, 但是总觉得有有关问题, 高手指教

2012-04-08 
这段代码能输出结果, 但是总觉得有问题, 高手指教#includestring.h #includestdio.h #includemalloc.

这段代码能输出结果, 但是总觉得有问题, 高手指教
#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

热点排行