ERROR C++ - [Error] ISO C++ forbids comparison between Pointer and integer [-fpermissive]

Asked

Viewed 1,798 times

0

I’m learning C++ and copied a code from the internet and gave it a modified one, but it presents the Error when compiling - [Error] ISO C++ forbids comparison between Pointer and integer [-fpermissive].

Code:

include iostream

include stdio.h

define SIZE 200

char nome[SIZE][50];

char sexo[SIZE][50];

int rg[SIZE][50];

int cpf[SIZE][50];

int tel[SIZE][50];

int idade[SIZE][50];

int op;

void cadastro();

void pesquisa();

int main(void) {

    cadastro();

    pesquisa();

}



void cadastro(){

    static int linha;

    do{

        printf("\nDigite o nome: ");

        scanf("%s", &nome[linha]);

        printf("\nDigite o sexo [F/M]: ");

        scanf("%s", &sexo[linha]);

        printf("\nDigite o RG: ");

        scanf("%d", &rg[linha]);

        printf("\nDigite o CPF: ");

        scanf("%d", &cpf[linha]);

        printf("\nDigite a idade: ");

        scanf("%d", &idade[linha]);

        printf("\nDigite o telefone: ");

        scanf("%d", &tel[linha]);

        printf("\nDigite 1 para continuar ou 2 para sair: ");

        scanf("%d", &op);

        linha++;

    }while(op==1);

}



void pesquisa(){

    int cpfPesquisa;

    int i;

    do{

        printf("\nDigite o CPF que deseja buscar: ");

        scanf("%d", &cpfPesquisa);

        for(i=0;i<SIZE;i++){

            if(cpf[i]==cpfPesquisa){

                printf("\nNome: %s\nSexo: %s\nCPF: %d\nRG: %d\nIdade: %d\nTelefone: %d", nome[i], 

sexo[i], cpf[i], rg[i], idade[i], tel[i]);


            }

        }

    printf("\nDigite 1 para continuar pesquisando: ");

    scanf("%d", &op);

    }while(op==1);  

}
  • Although you inform C++ your code is in C. Here: scanf("%s", &nome[linha]); and here: scanf("%s", &sexo[linha]); doesn’t have this & because they are strings. Note that you did not assign an initial value to the variable linha.

1 answer

0


Realize that int cpf[SIZE][50] is a 2D array. Therefore, by indexing only once the result will be a pointer to integer (since the resulting 1D array degenerates to a pointer), not an integer. This explains the error of comparing a pointer and an integer on the line with cpf[i] == cpfPesquisa. If you index once more then you will get an integer.

  • It would have to send an example, because I don’t know much C language.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.