![](/style/images/good.png)
![](/style/images/bad.png)
字符的的有规律替换。_wx6327119b9a154的技术博客_51CTO博客
source link: https://blog.51cto.com/u_15797078/5723693
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
字符的的有规律替换。
精选 原创要求:两字符数组有规律的替换,从外而内的依次替换
知识点:1.计算字符数组的长度表达式:int sz=sizeof(arr)/sizeof(arr[0])-2 或int sz=strlen(arr)-1
2.strlen()的库为#include<string.h>、sleep(1000)//休息一秒,以毫秒为单位,其库为#include<windows.h>、system("cls")的库为#include<stdlib.h>,其中“cls”为执行系统命令的一个函数:清空屏幕。
3.while循环
![字符的的有规律替换。_系统命令](https://s2.51cto.com/images/202209/591b217444a42644b8b1273fea070d4a75f194.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=,x-oss-process=image/resize,m_fixed,w_1184/format,webp)
![字符的的有规律替换。_字符数组_02](https://s2.51cto.com/images/202209/d5bfbf722c6e0a205d0990ccb1f0dfdacd7456.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=,x-oss-process=image/resize,m_fixed,w_1184/format,webp)
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<stdlib.h>
int main()
char arr1[]="hello*****!!!!!";
char arr2[]="###############";
int left=0;
int sz=sizeof(arr1)/sizeof(arr1[0])-2;//注意还有个\n,所以要减去2
//int right=strlen(arr1)-1;
int right=sz;
while(left<=right)
arr2[left]=arr1[left];
arr2[right]=arr1[right];
printf("%s\n",arr2);
//sleep(1000);//休息一秒。毫秒为单位。
//system("cls");//执行系统命令的一个函数:-cls-清空屏幕。
left++;
right--;
return 0;
注:各知识点的把握
- 赞
- 收藏
- 评论
- 分享
- 举报
上一篇:输入登录密码,可输入三次。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK