16,472
社区成员
发帖
与我相关
我的任务
分享
int func(int *nCount, char *p[]) /* 二维数组这么定义正确吗,为什么传不出呢? */
{
// 要把如下的字符串传出到p中,
strcpy(p[0],"test1");
strcpy(p[1],"test2123");
strcpy(p[2],"test3_25626");
strcpy(p[3],"te4");
*nCount = 4;
}
main()
{
char srcArr[50][50]; // 如何把函数中的值传递到srcArr数组中,
int nCount;
func(&nCount, srcArr); // 好像这么调用不正确?
}
func(50, 50, srcArr, &nCount);
// srcArr 出错: cannot convert parameter 3 from 'char [50][50]' to 'char *'
func(50, 50, srcArr, &nCount); // srcArr 出错: cannot convert parameter 3 from 'char [50][50]' to 'char *'
strcpy(p[0],"test1");
strcpy(p[1],"test2123");
strcpy(p[2],"test3_25626");
strcpy(p[3],"te4");
int func(int dimLen, int dimCount, char *p, int *nCount)
{
strcpy(p + 0 * dimLen,"test1");
strcpy(p + 1 * dimLen,"test2123");
strcpy(p + 2 * dimLen,"test3_25626");
strcpy(p + 3 * dimLen,"te4");
*nCount = 4; // 确保 nCount < dimCount
return nCount;
}
int main(int argc, char *argv[])
{
int nCount;
char srcArr[50][50];
func(50, 50, srcArr, &nCount);
}
void func(int *p, int n, int m)
{
for(int i=0; i < n; i++)
for(int j=0; j < m; j++)
p[i*m+j]=i+j;
}
void main(){
int a[2][3];
int *p = &a[0][0];
func( p, 2, 3);
cout << a[1][2] <<endl;
cout<<"end"<<endl;
return;
}
int func(int *nCount, char (*p)[50])