字符串循环右移问题?
来源:互联网 发布:网络审核员 编辑:程序博客网 时间:2024/04/28 19:51
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
void Reverse(char *str, int m, int n)
{
char temp;
char *front = str +m;
char *rear = str + n;
while(front<rear)
{
temp = *front;
*front = *rear;
*rear = temp;
front++;
rear--;
}
}
void LoopMove(char *pStr, int steps)
{
int len = strlen(pStr);
Reverse(pStr,0,len-steps-1);
Reverse(pStr,len-steps,len-1);
Reverse(pStr,0,len-1);
cout<<pStr<<endl;
}
int main()
{
//char* pStr = "abcdefghi";
char pStr[] = "abcdefghi";
int steps = 2;
LoopMove(pStr, steps);//output:hiabcdefg
return 0;
}
当主函数中字符串用数组表示时,代码可以正确运行,但是当主函数中数组用字符指针表示时,程序出错,unhandled exception, c0000005 access violation.不知哪位大牛能
分析下原因?
- 字符串循环右移问题?
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- 字符串循环右移
- Non-ASCII character '\xca' in file
- Uboot 之Makefile 分析
- keepalived源码浅析——pid文件
- mysql
- CentOS-6.4-x86_64-minimal Nginx编译和安装
- 字符串循环右移问题?
- 软件测试工具LoadRunner常用函数
- HDU 1166 敌兵布阵 (线段树)
- wifi 交互过程
- 朋友圈
- 如何在Oracle中复制表结构和表数据
- Hadoop使用JobControl设置job之间的依赖关系
- ios 类别(category)
- 如何加快flex程序启动时的加载速度