#include
#include
#include
void Test()
{
char arr1[] = "###############";
char arr2[] = "welcome to bit!";
int len = strlen(arr1);
/*int len = sizeof(arr1) / sizeof(arr1[0]);*/
int i = 0;
int left = 0;
int right = len - 1;
while (left <= right)
{
arr1[left] = arr2[left];
arr1[right] = arr2[right];
left++;
right--;
printf("%s", arr1);
printf("\n");
Sleep(1000);
}
}
int main()
{
Test();
system("pause");
return 0;
}
注意:int len = strlen(arr1);
/*int len = sizeof(arr1) / sizeof(arr1[0]);*/
不可以!!!
因为sizeof求取字符串长度时有‘\0‘长度。
strlen求取字符串长度时无'\0'长度,但也要遇到’\0‘才结束。因此:
arr[10] = {'a','b','c'} strlen(arr) = 随机值
sizeof(arr) = 3