title: compare string acquired with fgets and fscanf
body: <p>i need to compare a string acquired from stdin by fgets, with onother one acquired from file by fscanf (and write on file with fprintf). I necessarily have to use the two functions for read from stdin and file.
  How i can do that?
  because i've see that fgets store also "\0" byte, but fscanf no.</p>
  
  <p>this is the code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  
  typedef struct asd {
      char a[20];
      char b[20];
  } struttura;
  
  
  void stampa_file() {
  struttura *tmp = NULL;
  struttura *letto = NULL;
  FILE *file;
  
  tmp = (struttura *)malloc(sizeof(struttura));
  letto = (struttura *)malloc(sizeof(struttura));
  file = fopen("nuovoFile", "r");
  printf("compare:\n");\
  fgets(letto-&gt;a, sizeof(letto-&gt;a), stdin);
  fgets(letto-&gt;b, sizeof(letto-&gt;b), stdin);
  while(!feof(file)) {
      fscanf(file, "%s %s\n", tmp-&gt;a, tmp-&gt;b);
      printf("a: %s, b: %s\n", tmp-&gt;a, tmp-&gt;b);
      if(strcmp(letto-&gt;a, tmp-&gt;a) == 0 &amp;&amp; strcmp(letto-&gt;b, tmp-&gt;b)) {
          printf("find matching\n");
      }
  }
  free(tmp);
  free(letto);
  }
  
  int main() {
  struttura *s = NULL;
  FILE *file;
  
  s = (struttura *)malloc(sizeof(struttura));
  
  file = fopen("nuovoFile", "a+");
  printf("");
  fgets(s-&gt;a, sizeof(s-&gt;a), stdin);
  printf("");
  fgets(s-&gt;b, sizeof(s-&gt;b), stdin);
  fprintf(file, "%s%s\n", s-&gt;a, s-&gt;b);
  fclose(file);
  stampa_file();
  
  free(s);
  return 0;
  }
  </code></pre>