代码如下:
- //字符串翻转例子
- #include "stdio.h"
- #include "string.h"
- void revstr(char *);
- int main()
- {
- char str[] = "Zhen Shan Ren is good!";
- revstr(str);
- puts(str);
- }
- void revstr(char *str)
- {
- char *start, *end, temp;
- start = str;
- end = start + strlen(str) -1;
- while (start++ < end--) {
- temp = *start;
- *start = *end;
- *end = temp;
- }
- }
复制代码
|
|