Comparison of elements of a vector with "strcmp()"

Asked

Viewed 157 times

-2

In the following function I want to compare the elements of a array of 1000, but I can’t find a way to successfully compare them, even using strcmp().

void verifica_conta(int *ptr) {
    int i; //Posição
    for(i = 0; i < 1000; i++){
       if(strcmp(*ptr, *(ptr+i)) == 0) {
          printf("\tConta já existente\n");
    }
}
  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

2

It makes no sense to compare two integers with strcmp() since this function compares strings.

It would be something like that:

void verifica_conta(int *ptr) {
    for (int i = 0; i < 1000; i++) if (ptr[0] == ptr[i]) printf("\tConta já existente\n");
}

I put in the Github for future reference.

But it’s even likely that you have a logic error as well.

Browser other questions tagged

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