title: Caesar Cipher / file input not working
body: <p>I am working on a program to encrypt and decrypt a .txt file with the Caesar cipher. (keyboard input is optional)I have made an effort but am stumped.</p>
  
  <p>What i have right now is a basic or i guess somewhat elaborate menu structure already. 
  I have gotten to where i should be calling the information from the file and it just calls garbage or is garbage one way or the other.</p>
  
  <p>Here is my code it runs to the input part and then ends after the input. </p>
  
  <p>its option 1 option 1 and then any number and then it runs the file input and then ends.</p>
  
  <p>Thanks in advance. I have pretty much looked everywhere and tried it 3 or 4 different ways all to no avail.</p>
  
  <p>So what i want to know is what should i do to fix the file input and suggestions on how to then take that array or string how ever you suggest and change the ascii values of each character by the shift value. </p>
  
  <p>Thanks ahead of time. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cmath&gt;
  #include &lt;cctype&gt;
  #include &lt;cstring&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;dos.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  int decryptce();
  int encryptcefile();
  int encryptce();
  int outputce();
  int encmenu();
  int decmenu();
  
  int main()
  {
      int t;
        //main menu
      cout &lt;&lt; "-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt; "This is a Caesar Cipher, please select [1] or [2]" &lt;&lt; endl;
      cout &lt;&lt; "-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt; "[1] Encrypt"&lt;&lt;endl;
      cout &lt;&lt; "[2] Decrypt"&lt;&lt;endl;
      cout &lt;&lt; "What is your choice:\t";
      cin  &gt;&gt; t;
      cout &lt;&lt; "\n-----------------------------------------------------"&lt;&lt;endl;
  
      // menu switch statement
      switch (t)
      {
          case 1:
          {
              cout &lt;&lt; "\n running encryption:\n\n";
              encmenu();
              break;
  
          }
          case 2:
          {
              cout &lt;&lt; "\n running decryption:\n\n";
              decmenu();
              break;
          }
          default:
          {
              cout&lt;&lt; "Thats not a 1 or 2"&lt;&lt;endl;
              cout&lt;&lt; "Relaunch the program"&lt;&lt;endl;
              system ("pause");
              return 0;
          }
      }
  
      return 0;
  }
  
  int encmenu()
  {
  
      int t;
      cout &lt;&lt; "-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt; "You selected: Encrypt with Caesar Cypher"&lt;&lt;endl;
      cout &lt;&lt; "-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt;"Do you want to enter from a file or the keyboard?"&lt;&lt;endl;
      cout &lt;&lt;"Enter [1] From file, or [2] From Keyboard"&lt;&lt;endl;
      cout &lt;&lt;"Run option:\t";
      cin  &gt;&gt; t;
      cout &lt;&lt; "\n-----------------------------------------------------"&lt;&lt;endl;
      // encrypt menu switch
  
      switch (t)
      {
          case 1:
          {
              encryptcefile();
              break;
          }
          case 2:
          {
              encryptce();
              break;
          }
          default:
          {
              cout&lt;&lt; "Thats not a 1 or 2"&lt;&lt;endl;
              cout&lt;&lt; "Relaunch the Program"&lt;&lt;endl;
              system ("pause");
              return 0;
          }
      }
      return 0;
  }
  
  // decrypt main menu
  int decmenu()
  {
      int h;
      cout &lt;&lt; "-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt; "You selected: Decrypt with Caesar Cypher"&lt;&lt;endl;
      cout &lt;&lt; "-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt; "Reading from Data.txt in main file directory:";
      cout &lt;&lt; "\n"&lt;&lt;endl;
      cout &lt;&lt; "Ofset is:\t";
      cin  &gt;&gt; h;
      cout &lt;&lt; "\n-----------------------------------------------------"&lt;&lt;endl;
      return h;
  }
  
  int decryptce()
  {
      return 0;
  }
  
  
  int encryptcefile()
  {
      // for figuring out what to do with negatives
      /*
      letter = x;
      letter = ( letter + shift + 26 ) % 26;
      // add 26 in case the shift is negative
      letter += x; // back to ascii code
  
      */
      char c,i;
  
      int num=0;
      int shift;
      ofstream ofile;
      ifstream ifile;
      ifile.open("data.txt");
      ofile.open("Encrypted.txt");
      if(!ifile)
      {
          cout &lt;&lt; "Error Opening File" &lt;&lt; endl;
          return 0;
      }
      if(!ofile)
      {
          cout &lt;&lt; "Error Opening File" &lt;&lt; endl;
          return 0;
      }
  
      while (ifile.good())
      {
          c = ifile.get();
          if (c=='\n')num++;
          {
              cout &lt;&lt; "Is: " &lt;&lt; num &lt;&lt; " Long. \r";
              Sleep(1);
              fflush ( stdin );
          }
      }
  
      cout &lt;&lt; "File is: " &lt;&lt; num &lt;&lt; " characters Long.\n"&lt;&lt;endl;
      cout &lt;&lt; "\n-----------------------------------------------------"&lt;&lt;endl;
      cout &lt;&lt; "What is the shift for the encryption:\t";
  
      // ---------------------working here-------------------
      cin &gt;&gt; shift;
  
      const int xx = num+1;
      char *arraye;
      char *arrayce;
      int j;
  
      arraye = new char [xx];
      arrayce = new char [xx];
      arrayce[xx];
      ifile.read(arrayce,xx);
  
      for(j=0;j&lt;xx;j++)
      {
          arraye[j]=arrayce[j];
          cout &lt;&lt; arrayce[j]&lt;&lt; endl;
      }
  
      return 0;
  }
  
  int encryptce()
  {
      return 0;
  }
  
  int outputce()
  {
      return 0;
  }
  </code></pre>