mercredi 27 janvier 2021

Comparing 2 strings from a struct

I don't program in C for a good 2 years, I recently was ordered to make a program that uses a FIFO system, I'm really confused in how I'm going to search for a name using this method.

This is my struct:

struct Node {
  int price;
  char plat[25];
  char name[50];
  struct Node *next;
};
typedef struct Node node;

This is where I insert:

void insert(node *LINE) {
  line *new = alocar();
  new->next = NULL;

  if (empty(LINE))
    LINE->next = new;
  else {
    node *tmp = LINE->next;

    while (tmp->next != NULL)
      tmp = tmp->next;

    tmp->next = new;
  }
  size++;
}

Here is where I'm struggling, I'm just freestyling at this point, trying to figure out what works but nothing seems to be working, I'm trying to search for the name inside the struct using the nameu variable.

void search(node*LINE)
{
  if(empty(LINE))
  {
    printf("Line empty!\n\n");
    return;
  }
  // -------------------test----------------------
  char nameu[10];
  node *tmp;
  node n;

  if (scanf("%9s", nameu) != 1) return;
  while( tmp != NULL && strcmp(nameu, n.name) == 0)
  {
    printf("%6s", tmp->name);
    tmp = tmp->prox;
  }
}

The full code is in Portuguese so I only placed snippets of code that I translated, I'll post here the full code with translations only in the menu so that anyone trying to use it can comprehend what's going on.

https://pastebin.com/ZytqhcWF

Edit: I forgot to translate some variables

Aucun commentaire:

Enregistrer un commentaire