If you grab this code and run it, you'll see what I mean. The second half doesn't run, and when I can get it to run, it's all completely wrong. I'm trying, but I'm tired and just want to get it done...lol. The encrypt and decrypt are a separate cpp file, but I'll post them here as well.
#include "freefun.h"
using namespace std;
int main()
{
ofstream streamout;
ifstream streamin;
char infile[16];
char instring[100];
int i=0;
cout << "Please input the filename you would like to open up to 15 characters." << endl;
cin >> infile;
streamout.open (infile);
if (!streamout)
{
cout << "Unable to open file: " << infile << endl;
exit (1);
}
else
{
cout << "File " << infile << " opened." << endl;
}
while (i <=3)
{ i++;
cout << "Please enter your text." << endl;
cin >>instring;
encrypt(instring,5);
cout << "You entered: "<< instring << endl;
streamout<<instring<<endl;
}
cout << instring << endl;
streamout.close();
streamin.open(infile);
if (!streamin)
{
cout << "Unable to open file: " << infile << endl;
exit (1);
}
else
{
cout << "File " << infile << " opened." << endl;
}
while (i <=3)
{ i++;
cout << "Please enter your text." << endl;
cin >>instring;
encrypt(instring,5);
cout << "You entered: "<< instring << endl;
streamout<<instring<<endl;
decrypt(instring,5);
cout << "You entered: "<< instring << endl;
}
streamin.close();
return 0;
}
encrypt and decrypt
void encrypt(char *s,int n)//simple encryption method
{
for(int i=0;s[i]!=0;i++)
{
s[i] += n;
}
}
void decrypt(char *s,int n)
{
for(int i=0;s[i]!=0;i--)
{
s[i] += n;
}
}