【本文鏈接】
http://www.cnblogs.com/hellogiser/p/reverse-string.html
reverse string
【代碼】
C++ Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
version: 1.0
author: hellogiser
blog: http://www.cnblogs.com/hellogiser
date: 2014/5/30
*/
void swap(char *a, char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
char *reverse_str(char *str)
{
if(NULL == str)
return str;
unsigned int len = len_str(str);
char *start = str;
char *end = str + len - 1;
while(start < end)
{
swap(start, end);
start++;
end--;
}
return str;
}
【本文鏈接】
http://www.cnblogs.com/hellogiser/p/reverse-string.html