简体   繁体   English

类型“ int”的参数与参数类型“ int **”不兼容

[英]argument of type “int” is incompatible with parameter type “int **”

I'm writing a 2d array program and i'm having issues getting it to print out, I'm not sure if i'm doing my 2d array passing correct now as its crashing instead of running at all. 我正在编写一个2D数组程序,但在打印时遇到问题,我不确定我是否正在正确地通过2D数组,因为它崩溃了而不是运行了。 Any advice would be helpful 任何意见将是有益的

void initialize(int* one, int** two);
void replace(int* arr,int rows, int cols,int value);
void fill(int* arr, int rows, int cols);
void print(int** arr, int rows, int cols);

ofstream outfile;
ifstream infile;
int arrayOne[100][100];
int arrayTwo[100][100];

int main(){

    int rows,cols=0;

    cout << "Please input how many rows you would like in the array:  ";
    cin >> rows;
    cout << "Please input how many columns you would like in the array:  ";
    cin >> cols;

    fill(arrayOne[100][100],rows,cols);
    //print(arrayOne[100][100],rows,cols);

    system("pause");
    return 0;
}

void initialize(int* one, int* two){
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            arrayOne[i][j]=0;
            arrayTwo[i][j]=0;
        }
    }
}

void replace(int* arr,int rows,int cols,int value){
    arr[rows][cols]=value;
}

void fill(int* arr, int rows, int cols){
    int i=0;
    for(int r=0; r < rows; r++){
        for(int c=0; c < cols; c++){
            replace(arr,r,c,i++);
        }
    }
}

void print(int** arr, int r, int c){
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
}

If you read the error message, it plainly states your problem. 如果您阅读该错误信息,则可以清楚地说明您的问题。 That being said, it does not plainly state how to fix it. 话虽如此,它并没有明确说明如何解决它。 You're going down a rough path with fixed arrays... 您正在沿着固定阵列的艰难道路前进...

/* arrayOne[100][100] This is an 'int' at the 101st row and 101st column.
 * It isn't an address to anywhere in the array, in fact it is just beyond
 * the end of your array.
 *
 * Regardless, even if it were a pointer, it would point to a location in memory
 * that is not yours. We count starting with 0 in C/C++. So if you'd like to
 * reference the 'whole' array  just pass it bare:
 */
fill (arrayOne, rows, cols);

/* Of course this means that you need to fix the definition of 'fill'
 * and 'replace'.
 */
void replace(int arr[100][100],int rows,int cols,int value){
    arr[rows][cols]=value;
}

/* As you can see this isn't going to be friendly */
void fill(int arr[100][100], int rows, int cols){
    int i=0;
    for(int r=0; r < rows; r++){
        for(int c=0; c < cols; c++){
            replace(arr,r,c,i++);
        }
    }
}

You have other issues, but those can be asked in other questions when you run into them. 您还有其他问题,但是在遇到其他问题时可以提出这些问题。

Change all int* arr and int** arr to int arr[100][] or to arr[][100]. 将所有int * arr和int ** arr更改为int arr [100] []或arr [] [100]。 I don't remember which one. 我不记得是哪一个。 but, it's one of them for sure. 但是,肯定是其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “int”类型的参数与“int*”类型的参数不兼容 - argument of type “int” incompatible with parameter of type “int*” 类型为“ int”的参数与类型为“ int *”的参数不兼容 - Argument of type “int” is incompatible with parameter of type “int *” 类型“int”的参数与类型“int”的参数不兼容 - argument of type “int” incompatible with parameter of type “int” int(*)[] 类型的参数与“int**”类型的参数不兼容 - Argument of type int(*)[] is incompatible with parameter of type “int**” “ int”类型的参数与“ char”类型的参数不兼容 - Argument of type 'int' is incompatible with parameter of type 'char' 错误:参数类型int与参数类型不兼容 - ERROR: argument type int incompatible for parameter type “int”类型的参数与“HTREEITEM”类型的参数不兼容 - argument of type “int” is incompatible with parameter of type “HTREEITEM” “类型为 &#39;int(*)()&#39; 的参数与类型为 int 的参数不兼容”错误? - "argument of type ”int(*)()“ is incompatible with parameter of type int" error? “int*”类型的参数与“int**”类型的参数不兼容 C++ 中的错误 - argument of type “int*” is incompatible with parameter of type “int**” error in C++ “unsigned int *”类型的参数与“size_t *”类型的参数不兼容 - argument of type “unsigned int *” is incompatible with parameter of type “size_t *”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM