一、
编写这个“演示多个代码从两端移动从中间汇聚”代码时,需要调用许多函数如strlen函数,Sleep函数
和system函数,但是<stdio.h>头文件中没有上述函数,因此需要加对应的头文件
#include<string.h>---------->strlen函数,计算字符串长度。
#include<windows.h>------->Sleep函数,休眠函数,以毫秒为单位。
#include<stdlib.h>----------->system函数,system函数是C语言提供的与操作系统衔接的函数
//编写代码,演示多个代码从两端移动从中间汇聚;
#include<stdio.h>
#include<string.h>//strlen 函数,计算字符串长度,不算结束符/0
#include <windows.h>//Sleep休眠函数
#include<stdlib.h>//用系统命令cls完成清屏操作。
int main()
{
char arr1[] = "welcome to bit !!!!!!";//两个数组进行替换替换一次打印一次
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(500);//休息0.5s
system("cls");//system函数是C语言提供的与操作系统衔接的函数
//执行系统命令的一个函数-cls:清空屏幕
left++;
right--;
}
printf("welcome to bit !!!!!!");
return 0;
}