title: command line arguments and files
body: <p>So I have a txt file that looks like this.</p>
  <p><strong>Input1.txt</strong></p>
  <pre><code>!
  awesome is
  
  Joseph
  guess I
  </code></pre>
  <p>the main point is to create a code that will rearrange the inputs into a readable sentence like this</p>
  <p><strong>answ1.txt</strong></p>
  <pre><code>I guess Joseph is awesome !
  </code></pre>
  <p>I have my code here</p>
  <p><strong>lab.txt</strong></p>
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;fstream&gt;
      using namespace std;
  
  
  
  struct nodeinfo
  {
      string word;
      nodeinfo * next;
  };
  
  
  void add (string inputword, nodeinfo ** ref)
  { 
      //create new node
      nodeinfo * temp = new nodeinfo();
      nodeinfo * temp2 = *ref;
  
      //word into node
      temp -&gt;word = inputword;
      //since its LIFO, temp is last so its next has to be NULL
      temp-&gt;next = NULL;
  
      //if list is empty, then the new node is the head
      if (*ref == NULL)
      {
          *ref = temp;
          return;
      }
      //if not empty, we go to last node
      //change second to last to temp
      while(temp2-&gt;next!=NULL)
      {
          temp2 = temp2-&gt;next;
      }
      temp2-&gt;next = temp;
      return;
  
  }
  
  void rewind(nodeinfo * lead)
  {
      if (lead == NULL)
      {
          return;
      }
      rewind(lead-&gt;next);
      cout &lt;&lt; lead -&gt;word&lt;&lt; &quot; &quot;;
  
  
  }
  
  int main(int argc, char *argv[])
  {
      
      if (argc &gt;=1)
      {
      freopen(&quot;output.txt&quot;, &quot;w&quot;, stdout);
      fstream file;
      string filename;
      filename = argv[0];
      string word;
      nodeinfo *head = NULL;
      file.open(filename);
      while(file &gt;&gt; word)
      {
          //pass ref pointer and word
      add(word, &amp;head);
      }
      rewind(head);
      return 0;
      }
  }
  
     
  </code></pre>
  <p>if I manually input my input file name as &quot;input.txt&quot; in my code like this</p>
  <pre><code>file.open(&quot;input1.txt&quot;)
  </code></pre>
  <p>it will work, but I am having a hard time using arc and argue to open my file and do what I want it to do.</p>
  <p>ideally, I would call my program to work like this</p>
  <pre><code>./input1.txt 
  </code></pre>
  <p>can anyone offer me solutions and what not?</p>