C/C++ | 23-12 用指针的方法,将字符串“ABCD1234efgh”前后对调显示

来源:互联网 发布:linux mysql 停止 编辑:程序博客网 时间:2024/05/17 07:53
/*
用指针的方法,将字符串“ABCD1234efgh”前后对调显示

*/


#include <stdio.h>  #include <stdlib.h>#include <iostream>#include <string.h>#include <assert.h>using namespace std;int  main(){char str[] = "ABCD1234efgh";int length = strlen(str);char *p1, *p2;p1 = str;p2 = str + length - 1;while (p1 < p2){char c = *p1;*p1 = *p2;*p2 = c;p1++;p2--;}printf("str now is %s\n", str);system("pause");return 0;}


阅读全文
0 0
原创粉丝点击