- 指针反转
void indicator_resver(char *cha)
{
// 指向第一个字符
char *begin = cha;
// 指向最后一个字符
char *end = cha + (strlen(cha) - 1);
while (begin < end) {
char temp = *begin;
*begin = *end;
*end = temp;
++begin;
--end;
}
}
char greet[] = "Hello,World";
indicator_resver(greet);
- 数组字符串反转
void array_resver(char *cha)
{
char *s = cha;
NSInteger length = strlen(s);
for (NSInteger i = 0 , j = length - 1; i < j; i++ ,j--) {
char temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
char greet[] = "Hello,World";
array_resver(greet);
网友评论