0

字符的的有规律替换。_wx6327119b9a154的技术博客_51CTO博客

 1 year ago
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.

字符的的有规律替换。

精选 原创

Find8 2022-09-29 18:21:40 ©著作权

文章标签 #include 系统命令 字符数组 文章分类 C/C++ 编程语言 阅读数219

要求:两字符数组有规律的替换,从外而内的依次替换

知识点: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循环

字符的的有规律替换。_系统命令
字符的的有规律替换。_字符数组_02

#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;

注:各知识点的把握

  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK