现在的位置: 首页 > 综合 > 正文

一道题_20121220

2017年12月11日 ⁄ 综合 ⁄ 共 326字 ⁄ 字号 评论关闭

开始写写博客,做做笔记,学习学习。

//利用指针的方法将"ADCD1234efgh"前后对调

#include <iostream>
#include <stdlib.h>
using namespace std;

char * swap(char * s)
{
	char * p1 = s;
	char * p2 = s + strlen(s) - 1;
	char temp = '\0';
	while(p1 < p2)
	{
		temp = *p1;
		*p1 = *p2;
		*p2 = temp;
		p1++;
		p2--;
	}
	return s;

}

int main()
{
	char s[100];
	cout << "请输入一串字符:";
	cin >> s;
	cout << "显  示  结  果:" << swap(s) << endl;
	system("pause");
	return 0;
}

显示结果:

抱歉!评论已关闭.