if anyone can check out my program below and see whats wrong, itd be greatly appreciated.

my goal:
user input a text file (i.e. data.txt) to open and read
print the mssg within file to both console and text file (i.e. secret.txt)
print the mssg as scrambled message (ASCII)

my problem:
-- it doesn't print out the scrambled version.
it DOES print out scrambled letters that are within the "data.txt"
but it doesnt OPEN the data.txt file and print the mssg within the file. just the data.txt words.

any suggestions?

current program:

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
  ifstream fin;
  
  string fileName;
  cout << "What file do you want to use for input? ";
  getline(cin, fileName);
  fin.open(fileName.c_str());
  
  ofstream fout;
  fout.open("secret.txt", ios::app);
  if( !fin.is_open() )
    {
      fout << "Can't open the file\n";
      fout.close();
      return 1;
    }
  
  string s;
  while (getline(fin, s))
  {
    string s = "data.txt"; // an example
    for (unsigned int i = 0; i < s.length(); i++) // for each char in the string...
    s[i]++; // bump the ASCII code by 1 
    
    cout << s << endl;
    fout << s << endl;
  } //  while

  fout.close();
  fin.close();
  cin.ignore();
  cin.get();
  return 0;
}

>> string s = "data.txt"; // an example
Delete that line

commented: thank you for your repetitive help! +1

holy crap! genius. thanks. =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.