我的答案!供参考!递归实现,可反转任意长度的字符BUFFER!VC++2008通过!
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
void reverse(char *a,unsigned int l)
{
unsigned int count=l/sizeof(char);
if(count>=2)
{
int h=count/2;
char *temp=new char[h];
for(int i=0;i<h;i++){*(temp+i)=*(a+i);};
for(int i=0;i<h;i++){*(a+i)=*(a+(count-h)*sizeof(char)+i);};
for(int i=0;i<h;i++){*(a+(count-h)*sizeof(char)+i)=*(temp+i);};
delete[] temp;
reverse(a,h*sizeof(char));
reverse(a+(count-h)*sizeof(char),h*sizeof(char));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char a[200];
ZeroMemory(a,sizeof(a));
gets(a);
reverse(a,strlen(a)*sizeof(char));
cout<<a;
Sleep(4000);
return 0;
}