title: How do I compare the words in the DS's and print the translation?
body: <p>I'm making a translation program in c to output raw word translations from English to Spanish. I've managed to break down the input string and store the words separately in a linked list, I also split the translation combo separated by commas in a text file, and stored that in a structure. Now my issue is, how do I compare both and print the translation result effectively? The last attempt I tried is in the code below which did not yield any results. The program should compare the English to the Spanish words, find a match in the dictionary, and print the Spanish translation without grammatical considerations. Thanks in advance.<a href="https://i.stack.imgur.com/n9Gp1.jpg" rel="nofollow noreferrer">My current output</a>
  Format of my dictionary: one, uno</p>
  <p><a href="https://i.stack.imgur.com/wcoKa.jpg" rel="nofollow noreferrer">Dictionary format</a></p>
  <pre><code>/*Project- English to Spanish Translator*/
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  // ----------User Definitions---------------//
  #define MAX_SIZE 1000
  
  //------------Data Structure--------------//
  // Implementation of a Doubly Linked List
  struct Dictionary
  {
      char word[50];
      struct Dictionary *prev; 
      struct Dictionary *next; 
  
  } * head; // points to the first node in the link list
  
  // Structure to store file values
  typedef struct F_Dict
  {
      char engword[50];
      char esword[50];
  } * dict;
  
  // ----------Function Prototypes----------//
  void get_word(char arr[]);
  void insert_word(char *word);
  void displayAll();
  void translate(struct Dictionary *node, FILE *fp);
  
  int main()
  {
      //-------------File Operations-------------------//
      FILE *dict;
      dict = fopen(&quot;dictionary.txt&quot;, &quot;r&quot;);
      //-----------Global Variables-----------------------//
      head = NULL;
      char input[MAX_SIZE];
  
      //--------------User Input-----------------------//
      printf(&quot;\nPlease enter a sentence in English: &quot;);
      fgets(input, MAX_SIZE, stdin);
  
      get_word(input);
      translate(head, dict);
      // displayAll();
  
      fclose(dict);
      return EXIT_SUCCESS;
  }
  
  //----------Function Definitions----------//
  void get_word(char arr[])
  {
      char new_str[20][20];
      int i, j = 0, ctr = 0;
      for (i = 0; i &lt; strlen(arr); i++)
      {
          if (arr[i] == ' ' || arr[i] == '\0') // If Space or NULL is found assign it to new_str[ctr]
          {
              new_str[ctr][j] = '\0';
              ctr++;
              j = 0;
          }
          else
          {
              new_str[ctr][j] = arr[i];
              j++;
          }
      }
      for (i = 0; i &lt;= ctr; i++)
          insert_word(new_str[i]);
  }
  
  void insert_word(char *word)
  {
      struct Dictionary **head_ref = &amp;head; 
  
      struct Dictionary *dict = (struct Dictionary *)malloc(sizeof(struct Dictionary)); // Allocate node
  
      strcpy(dict-&gt;word, word); // Insert Data
  
      dict-&gt;next = (*head_ref); 
  
      dict-&gt;prev = NULL; 
  
      dict-&gt;next = (*head_ref); 
  
      if ((*head_ref) != NULL) 
      {
          (*head_ref)-&gt;prev = dict;
      }
      // Move the head to point to the new node
      (*head_ref) = dict;
  }
  
  void displayAll()
  {
      struct Dictionary **head_ref = &amp;head;
      struct Dictionary *last = *head_ref; // Intialising the last node to be equal to the first node when list is empty
      // Moving from start to end of the linked list
      while (head != NULL)
      {
          last = head;
          head = head-&gt;next;
      }
      // moves backward through all the nodes of the linked list and displays all information
      while (last != *head_ref)
      {
  
          printf(&quot;Words: %s\n&quot;, last-&gt;word);
  
          last = last-&gt;prev;
      }
      system(&quot;pause&quot;);
  }
  
  void translate(struct Dictionary *node, FILE *fp)
  {
      struct Dictionary **head_ref = &amp;node;
      struct Dictionary *last = *head_ref; // Intialising the last node to be equal to the first node when list is empty
      // Moving from start to end of the linked list
      while (node != NULL)
      {
          last = node;
          node = node-&gt;next;
      }
      if (!fp)
      {
          printf(&quot;File Error!&quot;);
      }
  
      char buff[1024]; // Store the first 1024 lines into the buffer
      int row_count = 0;
      int line_count = 0;
  
      dict values[999]; // struct array to store values
  
      int i = 0;
      while (fgets(buff, 1024, fp) &amp;&amp; last != *head_ref)
      {
          line_count = 0;
          row_count++;
  
          char *line = strtok(buff, &quot;,&quot;);
          while (line)
          {
              if (line_count == 0)
                  strcpy(values[i]-&gt;engword, line);
  
              if (line_count == 1)
                  strcpy(values[i]-&gt;esword, line);
  
              for (int j = 0; j &lt; sizeof(values); j++)
              {
  
              
                  if (strcmp(last-&gt;word, values[j]-&gt;engword) == 1)
                  {
                      printf(&quot;%s&quot;, values[j]-&gt;esword);
                  }
                  else
                  {
                      last = last-&gt;prev;
                      last++;
                  }
              }
              line = strtok(NULL, &quot;,&quot;); // update the field value
              line_count++;
          }
          i++;
      }
  
      // printf(&quot;%s  %s&quot;, values[j].engword, values[j].esword);
  }
  </code></pre>