Hello I'm not too experience with c++ but I've learned some of the basics. I tried making a small txt file encryption program however my output prints one too many times to the 2nd txt file. This occurs both when encrypting and decrypting.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>
using namespace std;
char path1[256], path2[256];
int EnORDe;
char a,b;
char newline='\r\n';
void encrypt();
void decrypt();
int main ()
{
cout<< "what is the path to the text file: ";
gets(path1);
cout<< "where do you want the new text file: ";
gets(path2);
cout << "would you like to encrypt or decrypt a file(1 or 2): ";
cin>>EnORDe;
cout<<newline;
if(EnORDe == 1)
{
encrypt();
}
else if(EnORDe == 2)
{
decrypt();
}
system("PAUSE");
return 0;
}
void encrypt()
{
ifstream text(path1);
a=('a'+'A'-'b')/'5';
ofstream myfile;
myfile.open (path2);
while(!text.eof())
{
text.get(b);
b+=a;
myfile <<b;
}
myfile.close();
return;
}
void decrypt()
{
ifstream text(path1);
a=('a'+'A'-'b')/'5';
ofstream myfile;
myfile.open (path2);
while(!text.eof())
{
text.get(b);
b-=a;
myfile <<b;
}
myfile.close();
return;
}
I believe my loop is simply running one too many times but I'm not sure how to fix it.
Thanks for any help.