您的位置:首页 > 其它

cci-Q1.2 C风格字符串反转

2013-07-08 18:28 429 查看
原文:

Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)

译文:

写代码翻转一个C风格的字符串。(C风格的意思是"abcd"需要用5个字符来表示,包含末尾的 结束字符)
C style string是指结尾有‘\0’结束符

void reverse(char *str) {
if (NULL == str) exit(-1);
char *end;
char tmp;
while (*end) {
end++;
}
end--;
while (str < end) {
tmp = *end;
*end-- = *str;
*str++ = tmp;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息