运行代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
int main(void)
{
//4.编写代码,演示多个字符从两端移动,向中间汇聚
char arr1[] = "welcome to bit";
char arr2[] = "##############";
int left = 0;
int right = sizeof(arr1)/sizeof(arr1[0]) - 2;
while (left <= right)
{
arr2[left] = arr1[left];
arr2[right] = arr1[right];
printf("%s\n", arr2);
Sleep(100);//S要大写
left++;
right--;
}
return 0;
}
解释:sizeof(arr1)/sizeof(arr1[0]) 是表示数组含元素的个数!