// strReverse.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
//、反转一个字符串。
void swap(char& a,char& b)
{
char tmp;
tmp=a;
a=b;
b=tmp;
}
void reverse( char * str)
{
//char tmp;
int len;
len = strlen(str);
for ( int i = 0 ;i < len / 2 ; ++ i)
{
//tmp = char [i];
//str[i] = str[len - i - 1 ];
//str[len - i - 1 ] = tmp;
swap(str[i],str[len - i - 1 ]);
}
}
int main(int argc, char* argv[])
{
char null[]="";
reverse(null);
printf("reverse(null):%s\n",null);
char a[]="A";
reverse(a);
printf("reverse(a):%s\n",a);
char b[]="AB";
reverse(b);
printf("reverse(b):%s\n",b);
char c[]="ABC";
reverse(c);
printf("reverse(c):%s\n",c);
char d[]="ABCD";
reverse(d);
printf("reverse(d):%s\n",d);
printf("Hello World!\n");
return 0;
}
/*
reverse(null):
reverse(a):A
reverse(b):BA
reverse(c):CBA
reverse(d):DCBA
Hello World!
Press any key to continue
*/