当前位置:网站首页>编写代码,多个字符从两端移动,向中间汇聚
编写代码,多个字符从两端移动,向中间汇聚
2022-07-22 22:59:00 【暴躁小程序猿】
编写代码,多个字符从两端移动,向中间汇聚
编写代码,多个字符从两端移动,向中间汇聚,效果图如下:
代码如下:
#include<stdio.h>
#include<string.h>
#include<Windows.h>
int main()
{
char arr1[]="welcome to bit!!!!!!";
char arr2[]="######################";
int left=0;
int right=strlen(arr1)-1;//注意strlen需要头文件否则会有警告
//使用头文件#include<strig.h>
while(left<=right)
{
arr1[left]=arr2[left];
arr2[right]=arr1[right];
printf("%s\n",arr2);
Sleep(1000);//休息1000毫秒(睡眠1秒),注意必须加上头文件#include<windows.h>
system("cla");//清空屏幕;
left++;
right—-;
}
printf("%s\n",arr2);
return 0;
}
strlen减去1原因:因为strlen求出来的是字符串的长度,从1开始的,而下标是从0开始的,所以要减去1才能获得对应的下标;
总结
希望对大家有帮助,记得关注加三连哦!
边栏推荐
- 论文阅读:The Perfect Match: 3D Point Cloud Matching with Smoothed Densities
- Go gin: multi file upload
- What if Alibaba cloud international forgets its member name or login password?
- 网络参数管理
- Flink高级API(三)
- Send benefits again! Calendar applet source code
- 关于常见排序的稳定性
- Textview shows endless content implementation -- full display, partial display
- 批量可视化目标检测标注框——YOLO格式数据集
- Can the formatted data of the USB flash disk be recovered? How to recover the formatted data of the USB flash disk
猜你喜欢

I can't be angry with "voluntary salary reduction". I'm naked. I'm three times in four days. How can it end like this?

Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life

气不过“自愿降薪”,裸辞面字节,四天三面,结局居然这样?

Send benefits again! Calendar applet source code

TextView展示不完的内容实现--全显示、部分显示

昇思易点通 | 经典卷积神经网络的深度学习解析

RPC-BDY(5)-服务自动注销、负载均衡

Typora set the title to automatically add sequence number

数的三次方根

为什么有的人把代码写的如此复杂?
随机推荐
appendToFile追加失败
Qgraicsview implementation palette
Spark troubleshooting -precondition eof: no length prefix available
Android安全专题-so逆向入门和使用ida动态调试
【JS 逆向百例】某公共资源交易网,公告 URL 参数逆向分析
C language minesweeping
RPC-BDY(5)-服务自动注销、负载均衡
Redis profile
Several ways of QT thread exit
SSH password free login configuration
Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life
This is not a true sense of the meta universe, which should have its own distinctive characteristics and unique development logic
哪种类型的模切机可用于纸?
Flink implements a window accumulation function through processfunction and timer Ontimer
MSG | 开源与结缘,昇思携梦前行!
uni-app进阶之内嵌应用【day14】
开发者分享|MindSpore Lite 体验,一键实现图像分割
类和对象上案例
C language function (1)
深度解析kube-scheduler调度上下文