title: Generating a raw bit stream as an output to pipe in another software
body: <p>So, I have been struggling with the following problem:
  I have a text file with millions of random numbers. They are pure text. I want to pipe it out to the input of another software that was supposed to get a bit stream (Dieharder is the software).
  It works with the /dev/urandom, like:</p>
  
  <pre><code>cat /dev/urandom | ./dieharder &lt;options&gt;
  </code></pre>
  
  <p>I've created a C routine like that to generate the binary raw output stream. It Converts the the ASCII code to decimal (like 0x0F = 15), and stream it out to stdout:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  int ASCIItoDec(char c);
  
  int main(int argc, char *argv[])
  {
      FILE *fpr;
      FILE *fpw;
      unsigned int i = 0;
      size_t size=0;
      char c;       
      unsigned int *buffer; 
      char *filename;
      buffer = (unsigned int *) malloc(100);
      filename = (char *) malloc(128);
  
      if (argc != 2) 
      {
          scanf("%s", filename);
          fpr = fopen(filename, "rb");
      }
      else 
      {
          filename = (char *) realloc(filename, strlen(argv[1] + 1));
          strcpy(filename, argv[1]);
          fpr = fopen(filename, "rb");
      }
      if (fpr == NULL)
      {
          return -1;
      }
      while (c = fgetc(fpr) != EOF)
      {
          size++;
      }
      rewind(fpr);
      buffer = (int *) realloc(buffer, (size)*sizeof(int));
      memset(buffer, 0, sizeof(buffer));
      i=0;
      c = fgetc(fpr);
      while (c != EOF)
      {
         if ((c != ' ') &amp;&amp; (c != '\r') &amp;&amp; (c != '\n') &amp;&amp; (c != '\t'))
         {
              buffer[i] = (unsigned int) ASCIItoDec(c);
         }
         else if (c == ' ')   
         { 
              buffer[i] = ' ';
         }
         c = fgetc(fpr);
         i++;
      }   
      fclose(fpr);
      i=0;
      //streaming output
      fwrite(buffer, size*sizeof(buffer), 1, stdout);
      return 0;   
  }
  </code></pre>
  
  <p>The Dieharder software exits informing EOF was reached with out performing any analysis.
  What could possibly be wrong? </p>