纪念逝去的岁月——C/C++字符串反转
几年前,我还不会写这个
输入: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++字符串反转的更多相关文章
- 纪念逝去的岁月——C/C++字符串回文
判断字符串是否是回文: 1. 输入:hello world dlrow olleh 输出:1 2. 输入:nihao hello 输出:0 代码 #include <stdio.h> #i ...
- 纪念逝去的岁月——C/C++字符串旋转
几年前,我还不会写这个 例如: 1.向右→旋转5个字符 输入:HelloWorld 输出:WorldHello 2.向右→旋转3个字符 输入:HelloWorld 输出:rldHelloWo 代码 # ...
- 纪念逝去的岁月——C++实现一个队列(使用类模板)
1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...
- 纪念逝去的岁月——C++实现一个栈(使用类模板)
这个版本是上个版本的加强版,上个版本的代码:http://www.cnblogs.com/fengbohello/p/4542912.html 目录 1.代码 2.运行结果 1.代码 1.1 调试信息 ...
- 纪念逝去的岁月——C++实现一个栈
1.代码 2.运行结果 1.代码 stack.cpp #include <stdio.h> #include <string.h> class ClsStack { priva ...
- 纪念逝去的岁月——C/C++排序二叉树
1.代码 2.运行结果 3.分析 1.代码 #include <stdio.h> #include <stdlib.h> typedef struct _Node { int ...
- 纪念逝去的岁月——C/C++二分查找
代码 #include <stdio.h> int binarySearch(int iList[], int iNum, int iX, int * pPos) { if(NULL == ...
- 纪念逝去的岁月——C/C++快速排序
快速排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...
- 纪念逝去的岁月——C/C++交换排序
交换排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...
随机推荐
- IBM AppScan 安全扫描:加密会话(SSL)Cookie 中缺少 Secure 属性 处理办法 分类: 数据安全 2014-06-28 11:35 2805人阅读 评论(0) 收藏
问题描述: 原因分析: 服务器开启了Https时,cookie的Secure属性应设为true: 解决办法: 1.服务器配置Https SSL方式,参考:https://support.micro ...
- android 入门-R文件的死与活
1.图片的名字Btn_Play R文件死了. 1.答:修改图片的名字btn_play R文件活了.
- 使用windows的远程桌面连接连接Ubuntu
想起来用笔记本连接一个windows server时只需要在远程桌面连接里面输入一下ip地址然后账号密码就可以了,十分简单.于是乎既然装了个Ubuntu当服务器使那么我就业来远程连接一下,由于wind ...
- C#交互功能的演化
(此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:Miguel de Icaza在最近发表的一篇博文中畅谈了Mono及其相关产品中的C#交互特性的演化情况. ...
- vector 之删除元素
删除指定位置的元素 删除vector中第5个位置的元素 vector<int> vec; //执行vector初始化操作 vector<; //获取第五个元素的iterator ve ...
- MapKit 添加大头针
#import "ViewController.h" #import <MapKit/MapKit.h> #import "MYAnnotation.h&qu ...
- Linux学习笔记(10)文本编辑器vim
vim是一个功能强大的全屏幕文本编辑器,是Linux/Unix最常用的文本编辑器,其作用是建立.编辑.显示文本文件.vim的特点是没有菜单,只有命令. vim主要有三种工作模式,分别为命令模式.插入模 ...
- 去除字符串中的html标记及标记中的内容
去除字符串中的html标记及标记中的内容 --1.创建函数 create function [dbo].[clearhtml] (@maco varchar(8000)) returns varcha ...
- SQLServer 维护脚本分享(11)部分DBCC及系统存储过程
--DBCC命令与用法 DBCC HELP('?') DBCC HELP('useroptions') DBCC USEROPTIONS WITH NO_INFOMSGS --当前DB的区及文件 DB ...
- LoadRunner参数化之数据取值和更新方式
其实看LR已经很久了,每次看到参数化的取值更新时,都没有看透,了解个大概就为止了,也确实挺搞脑子的. 现在理解下来 分成2部分 取值方式 Select next row 如何从数据列表中取值 Seq ...