此处想说一下感受,今天写着程序让我记忆深刻,(字符串长度是从0开始的)我想以后不会再犯这种低级错误了
//在屏幕上输出菱形图案
#include <stdio.h>#include <Windows.h>
int main()
{
char arr1[] = " ";
char arr2[] = "*************";
char arr3[] = " ";
int centreleft = strlen(arr2)/2;//6
int centreright = strlen(arr2)/2;
int left = 0;
int right = strlen(arr2)-1;
//strlen()字符串长度,头文件为#include <Windows.h>
while(centreleft>0)
{
Sleep(1000);//睡眠函数:单位ms。
arr3[centreleft] = arr2[centreleft];
arr3[centreright] = arr2[centreright];
centreright++;
centreleft--;
printf("%s\n",arr3);
}
printf("%s\n",arr2);
while(left <= right)
{
Sleep(1000);
arr2[left] = arr1[left];
arr2[right] = arr1[right];
left++;
right--;
printf("%s\n",arr2);
}
getchar();
return 0;
}