As far as I can see, "file" is never initialised. So your program will probably crash in line 31.
In line 32, if what you're trying to do is read from the opened file, you should be doing something like
1 2
|
string word;
input >> word;
|
to get the next word from the opened file, just like you do in lines 77 to 81, if that's not clear (my fault), consider commenting out lines 31 and 40, and following the @LendraDwi by using
1 2
|
infile.open(key);
outfile.open(code);
|
in lines 76 and 88.
Even better make "file" a string instead of char[80], and use something like
encrypt(file.c_str());
line 96 needs a semi-colon.
Also you never your output, so in encrypt() and decrypt(), you need to create an ofstream and dump your contents in it,
your process (encryption/encription) happens after the loop, meaning it will only operate on the last item not on all of them, and unless you only intend to scramble the first 5 characters of each item, you should get rid of the magic number "5" in lines 83 and 95 (what happens if the item is less than 5 characters long?)
For example, encrypt might look like:
1 2 3 4 5 6 7 8 9 10 11 12
|
ifstream infile(key);
ofstream outfile((string(key) + ".enc").c_str());
string item;
while(!infile.eof())
{
infile>>item;
for(int i = 0; i < item.size(); i++) item[i] += 2;
outfile << item;
}
outfile.close();
infile.close();
|
This will give you an output file with extension ".enc" containg your encrypted data.
There are many more changes to be made for robustness of the code, but I hope these few tips will help you understand why it's currently failing.