cyke1
December 3rd, 2007, 04:42 AM
Hey guys I need some help again. I need to create a program that will open a file and create a second file. The second file should be encrypted by reading the file by reading each character and adding 10 to the ASCII code. Here is what I have so far the thing I can't figure out is how to add 10 to the ASCII code. please help. The book says something about reinterpret cast but I'm not sure how to use it and if that is right. Thank for any help.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int SIZE = 51;
char fileName[SIZE];
fstream dataFile, outPut, inFile;
ofstream outFile(outPut);
cout << "This program encrypts a text file by addind 10 to the\n";
cout << "ASCII code of each character in the file, then writes\n";
cout << "a new text file.\n";
cout << "Enter the input file name: " << fileName << endl;
cin >> fileName;
cout << "Enter the output file name: " << outPut << endl;
cin >> outPut;
dataFile.open(fileName);
if (fileName)
{
return 0;
}
dataFile.write (reinterpret_cast<char *>(ASCII+10), sizeof(ASCII+10));
cout << "The file has been encrypted." << endl;
dataFile.close();
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int SIZE = 51;
char fileName[SIZE];
fstream dataFile, outPut, inFile;
ofstream outFile(outPut);
cout << "This program encrypts a text file by addind 10 to the\n";
cout << "ASCII code of each character in the file, then writes\n";
cout << "a new text file.\n";
cout << "Enter the input file name: " << fileName << endl;
cin >> fileName;
cout << "Enter the output file name: " << outPut << endl;
cin >> outPut;
dataFile.open(fileName);
if (fileName)
{
return 0;
}
dataFile.write (reinterpret_cast<char *>(ASCII+10), sizeof(ASCII+10));
cout << "The file has been encrypted." << endl;
dataFile.close();
return 0;
}