几年前,我还不会写这个

输入: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. golang exec Command

    package mainimport ( "fmt" "log" "os/exec")func main() { out, err := e ...

  2. 使用SQL语句向已有数据表添加约束

    如果向存在数据的表里添加约束,有可能会出现数据不符合检查约束而造成添加约束失败. 如: 这是一个表,为身份证号添加检查约束. USE DEmo--指向当前操作的数据库 GO ALTER TABLE E ...

  3. 兼容所有浏览器的JS动态显示当前日期时间

    <script type="text/javascript"> function show_cur_times(){ //获取当前日期 var date_time = ...

  4. hdu 4272 2012长春赛区网络赛 dfs暴力 ***

    总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  5. PMP - 项目管理思维导图

  6. Axure 全局辅助线(转)

    普通辅助线作用于当前页 全局作用于所有页面 , 包括新建页面 创建普通辅助线直接拉出来 创建全局辅助线 , 在拉出来的时候按住 Ctrl 默认情况下 , 颜色不同 辅助线可以多选 , 用拖选 或 按 ...

  7. 指针数组 vs 数组指针

        指针数组,故名思义,就是指针的数组,数组的元素是指针:     数组指针,同样,就是直想数组的指针.     简单举例说明:     int *p[2]; 首先声明了一个数组,数组的元素是in ...

  8. strust.xml

    使用strust2框架,实现跳转,请求对应路径 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTY ...

  9. 廖雪峰js教程笔记 2

    arguments JavaScript还有一个免费赠送的关键字arguments,它只在函数内部起作用,并且永远指向当前函数的调用者传入的所有参数.arguments类似Array但它不是一个Arr ...

  10. C#与mysql做ASP.NET网页数据库查询速度测试

    两种方法是:1,使用mysql数据库的存储过程:2,C#编码,做网页后台与mysql数据库连接,前台测试显示测试过结果下面我将分别讲解两种方法的具体实现. 1,使用mysql数据库的存储过程插入万条大 ...