2008-04-11
将字符串反向显示
int main()
{
char* src = "hello,world";
int len = strlen(src);
char* dest = (char*)malloc(len+1);//要为\0分配一个空间
char* d = dest;
char* s = &src[len-1];//指向最后一个字符
while( len-- != 0 )
*d++=*s--;
*d = 0;//尾部要加\0
printf("%s\n",dest);
free(dest);// 使用完,应当释放空间,以免造成内存汇泄露
return 0;
}
{
char* src = "hello,world";
int len = strlen(src);
char* dest = (char*)malloc(len+1);//要为\0分配一个空间
char* d = dest;
char* s = &src[len-1];//指向最后一个字符
while( len-- != 0 )
*d++=*s--;
*d = 0;//尾部要加\0
printf("%s\n",dest);
free(dest);// 使用完,应当释放空间,以免造成内存汇泄露
return 0;
}
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 512 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
某知名企业电话面试
delete 写道guixian 写道 具体也记不清楚是哪个星期的星期一了, ...
-- by GreenForest -
某知名企业电话面试
这帖我考虑收藏 没事翻出来看看
-- by laiseeme -
某知名企业电话面试
这个面试我觉得回答还是以你的理解为主,如果找本选课一定不要你 还有啊如果全E文. ...
-- by helyho -
某知名企业电话面试
顶你一个...
-- by foolish_bear -
这是什么算法?看不太明白 ...
混沌 分形 chaos fractal
-- by Eastsun






评论排行榜