welcom to my blog 演示多个字符从两端移动向中间汇聚

演示多个字符从两端移动向中间汇聚

==演示welcom to my blog ==

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
int main()
{
	char arr1[] = "welcom to my blog";
	char arr2[] = "#################";
	int left = 0;
	int right = strlen(arr1) - 1;
	while (left <= right)
	{
		arr2[left] = arr1[left];
		arr2[right] = arr1[right];
		printf("%s\n", arr2);
		Sleep(1000);
		system("cls");
		left++;
		right--;
	}
	
	system("pause");
	return 0;
}

在这里插入图片描述
几点说明

Sleep(1000); 的头文件 #include <windows.h>

Sleep函数:功 能: 执行挂起一段时间  用 法: unsigned sleep(unsigned seconds);
Sleep(1000); 表示程序暂停一秒

//暂停一秒 可以看到字符变化
不想让程序跑的太快
2.
system(“cls”); 的头文件#include<stdlib.h>
清空屏幕的作用不然会出现如图的效果,很丑啊。
在这里插入图片描述
3.
int right = strlen(arr1) - 1;
字符串的长度-1为数组最后一个的下标
字符的个数等于字符串的长度+1//因为有/0结束
4.
原理其实很简单。两个数组,让数组一对数组二进行依次覆盖。

最后

我感受到了一点点有意思的地方,就和我电脑第一次出现hello,world一样开心。
本来是元宵节就该发出来的博客,结果我写到一半,电脑也没关,就跑去看晚会去了,今天只能含着泪痛恨自己,没有收尾工作。

发布了22 篇原创文章 · 获赞 5 · 访问量 3214

猜你喜欢

转载自blog.csdn.net/weixin_45271990/article/details/104227069