简体   繁体   中英

Function Procura Matriz in C: Comparison between pointer and integer [enabled by default] Warning

I'm working with matrix in C and i'm getting a warning that I can't seem to solve.

The warning is: comparison between pointer and integer [enabled by default]

#include <stdio.h>
#include <stdlib.h>

int procura_matriz(int **m, int numero, int y, int k){

int i, j, trueOrFalse=0;

for(i=0;i<y*k;i++){             
    if (m[i]==numero){      
        trueOrFalse=1;      
        break;
    }
}

return trueOrFalse;
}

Main:

#include <stdio.h>

int main(){

int trueOrFalse;
int y=5, k=2;
int m[5][2] = {{1,2},{3,1},{5,12},{4,8},{29,10}};       
int numero =13;

trueOrFalse=procura_matriz(m, numero, y, k);

printf("\n0(Não tem numero) | 1 (Tem numero) -> %d\n", trueOrFalse);
return 0;
}

In your code, m is of type int ** , so, m[i] is of type int * and you cannot compare that with an numero which is an int , for sure.

Instead of using one index i , you can make use of two indexes, say, i and j controlled by y and k , in your function.

M is a 2d array. M[i] is an array. And you compare an array with a integer, so you get the warning. Change m[i] to m[i/y][i%y] to resolve

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM