大佬们分析下那个小细节出了问题呢 编译错误提示在底部 谢谢
#include<stdio.h>#include<string.h>
#include<stdlib.h>
int sort(char **myp1,int num1,char *myp2[30],int num2,char ***myp3,int *num3)
{
int i = 0,j = 0;
int tmplen = 0;
char *tmp = NULL;
char **p3 = NULL;
p3 = (char **)malloc((num1+num2) * sizeof(char *));
if(p3 == NULL)
{
return -1;
}
for(i=0; i<num1; i++)
{
tmplen = strlen(myp1[i]) + 1;
p3[i] = (char *)malloc(tmplen * sizeof(char));
if(p3[i] == NULL)
{
return -2;
}
strcpy(p3[i], myp1[i]);
}
for(j=0; j<num2; j++,i++)
{
tmplen = strlen(myp2[j]) + 1;
p3[i] = (char *)malloc(tmplen * sizeof(char));
if(p3[i] == NULL)
{
return-3;
}
strcpy(p3[i], myp2[j]);
}
tmplen = num1 + num2;
//排序
for(i=0; i<tmplen; i++)
{
for(j=i+1; j<tmplen; j++)
{
if(strcmp(p3[i],p3[j]) > 0)
{
tmp = p3[i];
p3[i] = p3[j];
p3[j] = tmp;
}
}
}
*myp3 = p3;
*num3 = tmplen;
return 0;
}
void sortFree01(char **p,int len)
{
int i = 0;
if(p == NULL)
{
return ;
}
for(i=0; i<len; i++)
{
free(p[i]);
}
free(p);
}
void sortFree02(char ***myp,int len)
{
int i = 0;
char **p = NULL;
if(myp == NULL)
{
return ;
}
p = *myp;
for(i=0; i<len; i++)
{
free(p[i]);
}
free(p);
*myp = NULL;
}
int main(void)
{
char *p1[] = {"aaaaa","vvvvv","dfgdfg","diufui"};
char buf2[10][30] = {"234343","87575","8364587","389465","3498"};
char **p3 = NULL;
int len1, len2, len3;
int ret = 0,i = 0;
len1 = sizeof(p1)/sizeof(*p1);
len2 = 5;
ret = sort(p1, len1, buf2, len2, &p3, &len3);
if(ret!=0)
{
printf("func sort()err:%d\n",ret);
return ret;
}
for(i=0; i<len3; i++)
{
printf("%s\n",p3[i]);
}
sortFree02(&p3,len3);
system("pause");
return 0;
}
//错误提示信息[Error] cannot convert 'char (*)[30]' to 'char**' for argument '3' to 'int sort(char**, int, char**, int, char***, int*)'