title: Whats wrong with my program? (C++)
body: <p>I am having some problems with my program that reads, finds words containing a phrase from a file and write the results to a file.</p>
  
  <p>Here is the whole program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;array&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void space();
  void intro();
  void again(string input3);
  
  bool isRunning = true;
  
  class ReadWriteFile 
  {
  
  
      public:
      string input;
      string input2;
      string file;
      string tmp;
  
      int numberOfLines = 0;
      int counter = 0;
  
      void fileName()
      {
          cout &lt;&lt; "  Enter the file name: ";
  
          cin &gt;&gt; input;
  
          file = input + ".txt";
  
          space();
          fileLength();
      }
  
      string fileLength()
      {
          ifstream fileStream (file/*.c_str()*/);
  
          if (fileStream)
          {
              while (fileStream &gt;&gt; tmp)
                  numberOfLines++;
              // cout &lt;&lt; numberOfLines;
              // space();
              fileInput();
          }
          else
          {
              cout &lt;&lt; "  Wrong Input";
              space();
              fileName();
          }
  
          fileStream.close();
      }
  
      void fileInput()
      {
          string arr1 [numberOfLines];
  
          ifstream fileStream (file/*.c_str()*/);
  
          for (int i = 0; i &lt; numberOfLines; i++)
          {
              fileStream &gt;&gt; arr1 [i];
          }
  
          fileStream.close();
          orderInput(arr1);
      }
  
      void orderInput(string *arr1)
      {
          string arr2[numberOfLines];
          int a = 0;
  
          //string arr2 [numberOfLines];
  
          cout &lt;&lt; "  Enter a search key phrase: ";
  
          cin &gt;&gt; input2;
  
          space();
  
          for (int i = 0; i &lt; numberOfLines; i++)
          {
              tmp = arr1[i];
              //cout &lt;&lt; tmp;
  
              if (tmp.find(input2) != string::npos)
              {
                  arr2[a] = tmp;
                  cout &lt;&lt; "  " &lt;&lt; tmp &lt;&lt; endl;
                  a++;
              }
          }
  
          space();
          writeFile (arr2);
      }
  
      void writeFile (string *arr2)
      {
          ofstream fileStream ("output.txt");
  
          for (int i = 0; i &lt; numberOfLines; i++)
          {
              fileStream &lt;&lt; arr2[i] &lt;&lt; endl;
          }
  
          fileStream.close();
  
          cout &lt;&lt; "  The results are located in the output text file named 'output'" &lt;&lt; endl;
      }
  };
  
  ReadWriteFile  rwf;
  
  int main ()
  {
      string input3;
  
      intro();
  
      while (isRunning = true)
      {
          rwf.fileName();
          cout &lt;&lt; "Do you want to run this program again? (y/n): ";
          cin &gt;&gt; input3;
          again(input3);
      }
  
      return 0;
  }
  
  void space()
  {
      string enters = "\n\n\n\n\n\n\n\n\n\n";
      string rule = 
      "  --------------------\n       ----------";
  
      cout &lt;&lt; endl &lt;&lt; rule  &lt;&lt; enters;
  }
  
  void intro()
  {
      cout &lt;&lt; endl &lt;&lt; endl &lt;&lt;
      " ########## ###### ##    ## ##########"&lt;&lt; endl &lt;&lt;
      "     ##     ##      ##  ##      ##"&lt;&lt; endl &lt;&lt;
      "     ##     ##       ####       ##"&lt;&lt; endl &lt;&lt;
      "     ##     ######   ####       ##"&lt;&lt; endl &lt;&lt;
      "     ##     ##      ##  ##      ##"&lt;&lt; endl &lt;&lt;
      "     ##     ###### ##    ##     ##"&lt;&lt; endl &lt;&lt;
      " "&lt;&lt; endl &lt;&lt;
      "  ##### ######   ####    #####  ##### ##   ##"&lt;&lt; endl &lt;&lt;
      " ##     ##      ##  ##  ##     ##     ##   ##"&lt;&lt; endl &lt;&lt;
      "  ####  ##      ######  ##     ##     ##   ##"&lt;&lt; endl &lt;&lt;
      "     ## ###### ##    ## ##     ##     #######"&lt;&lt; endl &lt;&lt;
      "     ## ##     ##    ## ##     ##     ##   ##"&lt;&lt; endl &lt;&lt;
      " #####  ###### ##    ## ##      ##### ##   ##"&lt;&lt; endl &lt;&lt;
      " "&lt;&lt; endl &lt;&lt;
      " ##########  #####   #####  ##"&lt;&lt; endl &lt;&lt;
      "     ##     ##   ## ##   ## ##"&lt;&lt; endl &lt;&lt;
      "     ##     ##   ## ##   ## ##"&lt;&lt; endl &lt;&lt;
      "     ##     ##   ## ##   ## ##"&lt;&lt; endl &lt;&lt;
      "     ##     ##   ## ##   ## ##"&lt;&lt; endl &lt;&lt;
      "     ##      #####   #####  ######"&lt;&lt; endl &lt;&lt; endl;
  }
  
  void again(string input3)
  {
      if (input3 == "y" || input3 == "Y" || input3 == "yes" || input3 == "Yes" || input3 == "YES")
      {
  
      }
      else if (input3 == "n" || input3 == "N" || input3 == "no" || input3 == "No" || input3 == "NO")
      {
              isRunning = false;
      }
  }
  </code></pre>
  
  <p>Here is the piece of code that I believe is causing my issues:</p>
  
  <pre><code>    void fileInput()
      {
          string arr1 [numberOfLines];
  
          ifstream fileStream (file/*.c_str()*/);
  
          for (int i = 0; i &lt; numberOfLines; i++)
          {
              fileStream &gt;&gt; arr1 [i];
          }
  
          fileStream.close();
          orderInput(arr1);
      }
  
      void orderInput(string *arr1)
      {
          string arr2[numberOfLines];
          int a = 0;
  
          //string arr2 [numberOfLines];
  
          cout &lt;&lt; "  Enter a search key phrase: ";
  
          cin &gt;&gt; input2;
  
          space();
  
          for (int i = 0; i &lt; numberOfLines; i++)
          {
              tmp = arr1[i];
              //cout &lt;&lt; tmp;
  
              if (tmp.find(input2) != string::npos)
              {
                  arr2[a] = tmp;
                  cout &lt;&lt; "  " &lt;&lt; tmp &lt;&lt; endl;
                  a++;
              }
          }
  
          space();
          writeFile (arr2);
      }
  
      void writeFile (string *arr2)
      {
          ofstream fileStream ("output.txt");
  
          for (int i = 0; i &lt; numberOfLines; i++)
          {
              fileStream &lt;&lt; arr2[i] &lt;&lt; endl;
          }
  
          fileStream.close();
  
          cout &lt;&lt; "  The results are located in the output text file named 'output'" &lt;&lt; endl;
      }
  </code></pre>
  
  <p>Edit: The program freezes at: "The results are located in the output text file named 'output'"</p>