字符串逆序

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

int main(void)
{
	char *src = "LiMing";	
	int len = strlen(src);
	
	char *dest = (char*)malloc(len + 1);
	
	char *d = dest;
	char *s = &src[len-1];
	
	while(len!=0)
	{
		*d++ = *s--;
		len--;
	}
	*d = 0;    //否则会乱码
	//尾部要加\0
	
	printf("dest = %s\n",dest);

	return 0;
}



posted @ 2012-07-17 18:33  wdliming  阅读(96)  评论(0编辑  收藏  举报