What is the solution to this comparison? [closed]

0

I'm programming in C for a college subject, we read a file and create some list methods to use in the program, basically I implement the structure of a list and use in a solution for a requested program. My problem is that, my code works and is syntactically correct, but there is a comparison of two items that is not working, which is affecting in the general operation of my program (because I should not enter information more than once in the list), I made debbugin and found that the finde function does not return at any time aux (which is a pointer), this causes my program to enter several times the same information (if I put it in the file that the program reads), I have another problem too , my program reads strings with accent and even using the locale, the application is not fixed, if you have any tips on this, would be of great help. Here is my code:

General comments in my fscanf I have an if that checks if find == null, this means that find ran the entire list and did not find an item it returns null, if it finds what was passed in the finde is found , it returns aux, that's my problem, if I put it to insert 3 equal items, in the end it checks the if (aux-> item.name == x.name & aux-> item.status = = x. state), does not come in to return aux, oq ta making repeated data enter in my program

    
asked by anonymous 28.10.2018 / 02:08

1 answer

1

To compare strings you need to use a specific function, strcmp or strncmp (preferable).

TipoApontador find(TipoItem x, TipoLista* lista)
{
  TipoApontador aux;
  if (lista->primeiro != NULL)
  {
    aux = lista->primeiro;
    while (aux != NULL)
    {
      // if (aux->item.nome== x.nome && aux->item.estado == x.estado)
      //   return aux;
      if (strncmp(aux->item.nome, x.nome, 100) == 0 && strncmp(aux->item.estado, x.estado, 100) == 0)
        return aux;
      aux = aux->prox;
    }
  }
  return NULL;
}
    
28.10.2018 / 02:43