问题解决:
通过这个代码你可能会更加理解数组的元素
#include<stdio.h>
#include<windows.h>
// 编写代码,演示多个字符从两端移动,向中间汇聚
int main()
{
char arr1[] = { "welcome to bit!!!!!!welcome to bit!!!!!!" };
char arr2[] = { "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" };
int left = 0, right = strlen(arr1);
while (left <= right)
{
arr2[left] = arr1[left];
arr2[right] = arr1[right];
printf("%s\n", arr2);
Sleep(300);//每输出一行停顿0.3秒(300毫秒)
left++;
right--;
}
return 0;
}
其中 #include<windows.h> 是为了调用Sleep函数(库函数);Sleep(毫秒)用于使控制输出打印每一行的间隔时间,效果如下:
w&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
we&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!
wel&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!!
welc&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!!!
welco&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!!!!
welcom&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!!!!!
welcome&&&&&&&&&&&&&&&&&&&&&&&&&&&!!!!!!
welcome &&&&&&&&&&&&&&&&&&&&&&&&&t!!!!!!
welcome t&&&&&&&&&&&&&&&&&&&&&&&it!!!!!!
welcome to&&&&&&&&&&&&&&&&&&&&&bit!!!!!!
welcome to &&&&&&&&&&&&&&&&&&& bit!!!!!!
welcome to b&&&&&&&&&&&&&&&&&o bit!!!!!!
welcome to bi&&&&&&&&&&&&&&&to bit!!!!!!
welcome to bit&&&&&&&&&&&&& to bit!!!!!!
welcome to bit!&&&&&&&&&&&e to bit!!!!!!
welcome to bit!!&&&&&&&&&me to bit!!!!!!
welcome to bit!!!&&&&&&&ome to bit!!!!!!
welcome to bit!!!!&&&&&come to bit!!!!!!
welcome to bit!!!!!&&&lcome to bit!!!!!!
welcome to bit!!!!!!&elcome to bit!!!!!!
welcome to bit!!!!!!welcome to bit!!!!!!
E:\C语言代码\Project1\x64\Debug\Project1.exe (进程 5920)已退出,代码为 0。
按任意键关闭此窗口. . .