一道题_20121220

版权声明:一辈子做程序员有何不可? https://blog.csdn.net/yoyo18520/article/details/8351698

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

//利用指针的方法将"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;
}

显示结果:

猜你喜欢

转载自blog.csdn.net/yoyo18520/article/details/8351698