首页 > 其他 > 详细

字符串反转---指针

时间:2015-10-06 16:42:46      阅读:252      评论:0      收藏:0      [点我收藏+]

 

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 
 6 int inverse(char *str1,char *str2)
 7 {
 8     char *p1 = str1;
 9     char *p2 = str2;
10     while (p1 < p2)
11     {
12         char c = *p1;
13         *p1 = *p2;
14         *p2 = c;
15 
16         ++p1;
17         --p2;
18     }
19     return 0;
20 }
21 int main()
22 {
23     char buf[] = "abcdefg";
24     char *p1 = buf;
25     char *p2 = buf + strlen(buf) - 1;
26     printf("原字符串是:%s\n", buf);
27     inverse(p1, p2);
28     printf("字符串反转后:%s\n", buf);
29     system("pause");
30     return 0;
31 }

 

字符串反转---指针

原文:http://www.cnblogs.com/linst/p/4857162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!