指针数组copy问题,为什么值传不过来?
程序代码:/*
实现两个字符串的合并,并且排序出来,采用的是三种二维指针的内存输入模型
*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char ** sortArray(const char ** array1, int count1, const char (*array2)[30], int count2)
{
char **buf = (char **)malloc((count1 + count2) * sizeof(char));
int i = 0, j = 0;
for (i = 0,j = 0; i < count1 + count2; i++,j++)
{
buf[i] = (char *)malloc(32 * sizeof(char));
if (i < count1)
{
strcpy(buf[i], array1[i]);
}
else
{
strcpy(buf[i], array2[j]);//为什么array2的值传不多来,
//buf[i] = *array2[j];//这条语句同上
}
/*printf("%s", array2[j]);*///而又为什么这条语句却可以实现打印,非常不解
printf("%s ", buf[i]);
}
return 0;
}
void main()
{
char *array1[] = { "1111xxx", "ccccc", "jkdsfj", "34343" };
int count1 = sizeof(array1) / sizeof(char *);
char array2[10][30] = { "xxxxxxxxxxxx", "yyyyyy", "zzzzz" };
sortArray(array1, count1, array2, 3);
system("pause");
}




回的太慢了