title: C read all input once optimization
body: <p>first I'm looking for optimization, fast time execution</p>
  <p>I would like to read data from input in C so here is my code (Linux)</p>
  <pre><code>int main(void) {
      char command_str[MAX_COMMAND_SIZE];
  
      while (!feof(stdin)) {
          fgets(command_str, MAX_COMMAND_SIZE, stdin);
          // Parse data
      }
      return EXIT_SUCCESS;
  }
  </code></pre>
  <p>According to this post <a href="https://stackoverflow.com/questions/732463/read-a-line-of-input-faster-than-fgets">Read a line of input faster than <code>fgets</code>?</a>  <code>read()</code> function seems to be the solution.</p>
  <p>The data input is like:</p>
  <pre><code>100 C
  1884231 B
  8978456 Z
  ...
  </code></pre>
  <p>From a file, so I execute my program like <code>./myapp &lt; mytext.txt</code></p>
  <p>It is not possible to know how many entries there is, it's could be 10, 10000 or even more.</p>
  <p><a href="https://stackoverflow.com/questions/5638999/effective-stdin-reading-c-programming">From this post</a></p>
  <blockquote>
  <p>Drop all the casts on malloc and realloc; they aren't necessary and clutter up the code</p>
  </blockquote>
  <p>So if I use a dynamic array my app will be slower I think.</p>
  <p>The idea is:</p>
  <blockquote>
  <ul>
  <li><p>Read the whole input in one go into a buffer.</p>
  </li>
  <li><p>Process the lines from that buffer.</p>
  </li>
  <li><p>That's the fastest possible solution.</p>
  </li>
  </ul>
  </blockquote>
  <p>If someone would help me. Thanks in advance.</p>