Life is Good.

Enhance Tech and English
随笔 - 65, 文章 - 20, 评论 - 21, 引用 - 0

导航

<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(1)

随笔分类

随笔档案

文章档案

Blogs

Websites for learning

搜索

  •  

最新评论

阅读排行榜

评论排行榜

char* 的reverse 方法

#include "stdafx.h"
#include 
<iostream>

char* CharReverse(char*& dest, const char *src)
{  
  
char *temp = dest; // 注意这里:用来记录dest的初始地址
  for (int n = strlen(src)-1;n>=0;n--)
    
*(dest++= *(src+n);

  dest 
= temp;

  
return temp;  // 注意这里:返回dest字符串的首地址
}

int _tmain(int argc, _TCHAR* argv[])
{
  
char *= "abc"
  
char *= (char *)malloc(strlen(a)+1);
  memset(b, 
0x00sizeof(strlen(a)+1));  // 注意这里:对malloc的buf进行初始化
  printf("%s\n", CharReverse(b,a));

  
return 0;
}
To do...

posted on 2011-03-08 23:29 Mike Song 阅读(332) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理