title: correct way to use fwrite and fread
body: <p>I wrote a program </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {
      FILE *fp;
      int r;
      char arr[] = "this is the string";
      char str[20] = {'\0'};
  
      fp = fopen("fwrite.txt", "w");
      fwrite(arr, 1, sizeof(arr), fp);
      fseek(fp, SEEK_SET, 0);
      r = fread(str, 1, sizeof(arr), fp);
  
      if(r == sizeof(arr))
          printf("read successfully\n");
      else
      {
          printf("read unsuccessfull\n");
          exit(1);
      }
  
      printf("read = %d\n", r);
      printf("%s\n", str);
  
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>I am trying to read in this way but I am not able to do it. What is the problem here, is it that I should put <code>&amp;str[i]</code> and run a loop for <code>fread</code> or will <code>fread</code> be able to put data in the <code>str</code>?</p>
  
  <p>I am getting junk and I don't understand why?</p>