字符串反转

表示还是想了一段时间的,C长时间没看比较晕了:

#include <iostream>
using namespace std;

char* reversal(char *test,int size)
{
    char *test1 = new char[size]; 
	int tmp = size-2 ;
	for (int i = 0; i <= tmp; ++i)
	{
		test1[i] = test[tmp-i];
	}
	test1[size-1]='\0';
	return test1;
}
int main()
{
    char a[]="abcdefg";
	int size = sizeof(a)/sizeof(*a);
    cout << reversal(a,size) << endl;
}

posted @ 2011-03-11 08:14  hailong  阅读(236)  评论(0编辑  收藏  举报