几年前,我还不会写这个

输入:hello world

输出:dlrow olleh

代码

 #include <stdio.h>
#include <string.h> void cvtstring(char * pStr)
{
if(NULL == pStr)
{
return ;
}
int iLen = strlen(pStr);
int iStart = , iStop = iLen / ;
int i = ;
for(i = iStart; i < iStop;i++)
{
char x = pStr[i];
/*printf("x = %c\n", x);*/
pStr[i] = pStr[iLen - - i];
pStr[iLen - - i] = x;
}
} int main()
{
char p[] = {"hello world"};
printf("src : [%s]\n", p);
cvtstring(p);
printf("dst : [%s]\n\n", p); printf("src : [%s]\n", p);
cvtstring(p);
printf("dst : [%s]\n", p); return ;
}

编译

$ g++ -o cvtstring cvtstring.cpp

运行

$ ./cvtstring
src : [hello world]
dst : [dlrow olleh] src : [dlrow olleh]
dst : [hello world]

再见……

纪念逝去的岁月——C/C++字符串反转的更多相关文章

  1. 纪念逝去的岁月——C/C++字符串回文

    判断字符串是否是回文: 1. 输入:hello world dlrow olleh 输出:1 2. 输入:nihao hello 输出:0 代码 #include <stdio.h> #i ...

  2. 纪念逝去的岁月——C/C++字符串旋转

    几年前,我还不会写这个 例如: 1.向右→旋转5个字符 输入:HelloWorld 输出:WorldHello 2.向右→旋转3个字符 输入:HelloWorld 输出:rldHelloWo 代码 # ...

  3. 纪念逝去的岁月——C++实现一个队列(使用类模板)

    1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...

  4. 纪念逝去的岁月——C++实现一个栈(使用类模板)

    这个版本是上个版本的加强版,上个版本的代码:http://www.cnblogs.com/fengbohello/p/4542912.html 目录 1.代码 2.运行结果 1.代码 1.1 调试信息 ...

  5. 纪念逝去的岁月——C++实现一个栈

    1.代码 2.运行结果 1.代码 stack.cpp #include <stdio.h> #include <string.h> class ClsStack { priva ...

  6. 纪念逝去的岁月——C/C++排序二叉树

    1.代码 2.运行结果 3.分析 1.代码 #include <stdio.h> #include <stdlib.h> typedef struct _Node { int ...

  7. 纪念逝去的岁月——C/C++二分查找

    代码 #include <stdio.h> int binarySearch(int iList[], int iNum, int iX, int * pPos) { if(NULL == ...

  8. 纪念逝去的岁月——C/C++快速排序

    快速排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...

  9. 纪念逝去的岁月——C/C++交换排序

    交换排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...

随机推荐

  1. Windows 历史

  2. list[C++]

    //双向链表 #include <iostream> using namespace std; #include <list> int main(int argc, const ...

  3. windows下R语言在终端的运行

    在windows下可以有多种方式来运行R,R导论的这些章节给出一些详细的指导. 通常在环境变量离包含R的安装目录类似于R\R-3.1.2\bin\x64的情况下,就可以在CMD下运行R程序了 注意我这 ...

  4. 笑谈Android图表-MPAndroidChart

    MPAndroidChart是一款基于Android的开源图表库,MPAndroidChart不仅可以在Android设备上绘制各种统计图表,而且可以对图表进行拖动和缩放操作,应用起来非常灵活.MPA ...

  5. loadrunner生成随机数

    loadrunner生成随机数一: 对网站注册进行压力测试时,需要对注册的用户名进行参数化,因为可以会用到大量的测试数据,所以选择通过生成随机数来进行参数化.最开始用loadrunner自带的参数随机 ...

  6. js:方法2. 字符串

    String.charAt()/String.charCodeAt() string.charAt(n); n:The index of the character that should be re ...

  7. 解决Genymotion无法创建新设备或无法显示设备列表问题

    准备工作: 链接: https://pan.baidu.com/s/1i5v4IBN 密码: jc3m 用2.8的和最新VirtualBox-5.1.10-112026-Win 注意事项: 1.笔记本 ...

  8. Lost Cows

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9669   Accepted: 6228 Description N (2 ...

  9. 【CLR in c#】参数

    1.可选参数和命名参数 设计一个参数时,可为部分或全部参数分配默认值,调用这些方法的代码可以选择不指定部分实参,接受默认值,还可以通过制定参数名称的方式传递实参.如下 class CLR可选参数 { ...

  10. 点击 Run 之后发生了什么?

    这是我以前去链家网面试的一个题目,当时回答不够全面,现在看了2016 WWDC以及Sunnyxx iDev大会的分享之后,感觉对这个问题有了一些简单的认识,就来总结下.如果大家有补充,麻烦评论下哦! ...