title: Getting junk values when reading a string from File
body: <p>I am trying to read some data from a text file in my c program but getting junk values. </p>
  
  <p>Below is the input format in the file </p>
  
  <pre><code>3442
  Tack Hammer
  9
  3.550000
  ABC317
  </code></pre>
  
  <p>Here is my code to read this file data</p>
  
  <pre><code>char name[100];
  int product_code;
  
  fscanf(fin, "%d", &amp;x[i].product_code); //taking id from file is fine
  printf("\n%d\n",x[i].product_code); // works correctly
  
  fscanf(fin,"%[^\n]",name);
  printf("Data from file:\n%s",name);  // it displays junk values
  </code></pre>
  
  <p>Here is the output preview</p>
  
  <p><img src="https://i.stack.imgur.com/jxpT7.png" alt="enter image description here">
  can someone correct me please. thank you</p>