title: Random bytes with fread
body: <h1>#post</h1>
  <h2>The names of my variables are not imporant! This code will be deleted when it works!</h2>
  <h1>#post</h1>
  <p>Alright, so I'm using fread in stdio.h to read a text file. The problem is that I keep
  reading random bytes that don't exist in the text file from my knowledge.
  I'm assuming they are part of files scheme, but I just wanna make sure it's not my code.</p>
  <pre><code>#include &quot;stdafx.h&quot;
  #ifdef WIN32
      #include &lt;io.h&gt;
  #else
      #include &lt;sys/io.h&gt;
  #endif
  #include &lt;fcntl.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;stdio.h&gt;
  
  #include &quot;n_script_timer.h&quot;
  //using namespace std;
  
  #ifdef _INC_WCHAR
      typedef wchar_t CHR;
  #else
      typedef char CHR;
  #endif
  int _tmain(int argc, CHR* argv[])
  {
      #ifndef _DEBUG
          if(argc == 1)
          {
              printf(&quot;You must drag a file onto this program to run it.&quot;);
              scanf(&quot;%*c&quot;);
              return 0;
          }
          CHR* fname = argv[1];
      #else
          #ifdef _INC_WCHAR
              const CHR fname[16] = L&quot;f:\\deleteme.bin&quot;;
          #else
              const CHR fname[16] = &quot;f:\\deleteme.bin&quot;;
          #endif
      #endif
  
      FILE* inFile;
      long len;
      struct Script_Timer a;
      //static const int bsize = 4096*6;
      static const int bsize = 84;
      typedef CHR chhh[bsize];
      int alen;
      printf(&quot;#Opening File '%s' ...\n&quot;,fname);
      #ifdef _INC_WCHAR
          if((inFile = _wfopen(fname,L&quot;rb&quot;)) == NULL)
      #else
          if((inFile = fopen(fname,&quot;r&quot;)) == NULL)
      #endif
      {
          printf(&quot;Error opening file '%s' &quot;,fname);
          return 0;
      }
      fseek(inFile,SEEK_SET,0);
      #ifdef _WIN32
          len = _filelength( inFile-&gt;_file );
      #else
          len = _filelength(inFile-&gt;_fileno);
      #endif
      printf(&quot;  !FileLength: %d\n&quot;,len);
      printf(&quot;#Creating Buffers...\n&quot;);
      if(((float)len/(float)bsize) &gt; (len/bsize))
      {
          alen = (len/bsize) + 1;
      }
      else alen = (len/bsize);
      #ifdef WIN32
          //chhh *cha = new chhh[alen];
          chhh cha[alen];
      #else
          chhh cha[alen];
      #endif
      printf(&quot;#Reading File...\n&quot;);
      Start_ST(&amp;a);
      int i = 0;
      for(i=0;i&lt;alen;++i)
      {
          fread(&amp;cha[i],sizeof(CHR),bsize,inFile);
          printf(&quot;[%i]%s&quot;,i,cha[i]);
      }
      End_ST(&amp;a);
      fclose(inFile);
      printf(&quot;Characters per millisecond: %f \n&quot;,((float)len/a.milliseconds));
      printf(&quot;Characters per second: %f \n&quot;,((float)len/a.milliseconds) * 1000);
      scanf(&quot;%*c&quot;);
      return 0;
  }
  </code></pre>