// temp.cpp : Defines the entry point for the console application.
//#include "stdafx.h"int convert(int b[]);int main(int argc, char* argv[])
{
int a[3][6];

a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;
a[2][0] = 7;
a[2][1] = 8;
a[2][2] = 9; convert( a );
return 0;
}int convert(int b[])
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
num = b[i*3+j];
printf("hello %d\n",num);
} return 1;
}
错误提示::\My Documents\zej\temp\temp.cpp(22) : error C2664: 'convert' : cannot convert parameter 1 from 'int [3][6]' to 'int []'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.如何修改可以运行

解决方案 »

  1.   

    int convert(int b[][])
    {
    int i,j;
    int num; for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
    //num = b[i*3+j];
    printf("hello %d\n",b[i][j]);
    } return 1;
    }
      

  2.   

    int convert(int b[][])
    {
    int i,j;
    int num; for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
    num = b[i*3][j];
    printf("hello %d\n",num);
    } return 1;
    }
      

  3.   

    :\My Documents\zej\temp\temp.cpp(6) : error C2087: '<Unknown>' : missing subscript
    C:\My Documents\zej\temp\temp.cpp(22) : error C2664: 'convert' : cannot convert parameter 1 from 'int [3][6]' to 'int [][1]'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:\My Documents\zej\temp\temp.cpp(26) : error C2087: '<Unknown>' : missing subscript
    Error executing cl.exe.temp.exe - 3 error(s), 0 warning(s)
      

  4.   

    本程序的目的是为了让此C程序 在VC里编译通过运行对于b[][] vc编译一直提示出错请帮忙  谢谢
      

  5.   

    #include "stdafx.h"int convert(int* b);int main(int argc, char* argv[])
    {
    int a[3][6];

    a[0][0] = 1;
    a[0][1] = 2;
    a[0][2] = 3;
    a[1][0] = 4;
    a[1][1] = 5;
    a[1][2] = 6;
    a[2][0] = 7;
    a[2][1] = 8;
    a[2][2] = 9; convert( a );
    return 0;
    }int convert(int* b)
    {
    int i,j;
    int num; for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
    num = b[i*3+j];
    printf("hello %d\n",num);
    } return 1;
    }
      

  6.   

    a为指向二维数组的指针,而convert()的形参为指向一维数组的指针,两者类型不符,二维数组指针指向数组首行的地址,而一维数组指针指向数组首元素的地址。*a指向数组首行首元素的地址,相当于&a[0][0]。
      

  7.   

    调用时改为:
    convert(a[0]);
      

  8.   

    现在恢复的帖子还是提示错误啊:C:\My Documents\zej\temp\temp.cpp(22) : error C2664: 'convert' : cannot convert parameter 1 from 'int [3][6]' to 'int []'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.temp.exe - 1 error(s), 0 warning(s)
      

  9.   

    依我看,只好这样了:convert(a[0]);
    convert(a[1]);
    .............//依此类推.
      

  10.   

    我的方案你试了吗?
    调用时改为:
    convert(a[0]);
      

  11.   

    #include "stdafx.h"int convert(int* b);int main(int argc, char* argv[])
    {
    int a[3][3];

    a[0][0] = 1;
    a[0][1] = 2;
    a[0][2] = 3;
    a[1][0] = 4;
    a[1][1] = 5;
    a[1][2] = 6;
    a[2][0] = 7;
    a[2][1] = 8;
    a[2][2] = 9; convert( (int *)&a );
    return 0;
    }int convert(int* b)
    {
    int i,j;
    int num; for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
    num = b[i*3+j];
    printf("hello %d\n",num);
    } return 1;
    }