How to pass a filename when executing a C program
<p>I am trying to not hardcode the name of the input file in my C program. I have all of the other components working when I hardcode the filename. But would like to be able to pass it a string filename.
I am trying to execute compile a file called <code>Matrix.c</code> and name its executable <code>matrix</code>.</p>

<p>So, in terminal, when I get to my working directory. </p>

<pre><code>gcc -g Matrix.c -o matrix
</code></pre>

<p>then when I compile</p>

<pre><code>./matrix 
</code></pre>

<p>It doesn't have a filename passed to it so I am gonna check for that and have the user input a filename to load.</p>

<p>However, when someone passes the filename, should it be passed as:</p>

<pre><code>./matrix filename.txt
</code></pre>

<p>or</p>

<pre><code>./matrix &lt; filename.txt
</code></pre>

<p>With the latter option, I can't seem to get the name of the argument passed to the function from <code>argv[1]</code> — it's just "(Null)".</p>

<p>I know this is very simplistic question. But am I just completely off my rocker? Is it something to do with me running on OS X El Capitan. I know I've used the '&lt;' convention before. </p>