Is there a way to make a (char) array with a variable length?
I'm (kind of) working on an "encryption program" that takes a file and encrypts it using a ridiculously simple algorithm (if you can even call it that).
The problem is, when it asks the user to input the file name (including the extension and directories), if the file name is longer than the array 'name1' then there is an error that pops up after the program exits (even though everything encrypts and works out OK).
I really just need to know if I can create an array that has a variable length.
using namespace std;
bool badfilename = false;
fstream file1;//source file
fstream file2;//destination file
Encryption::Encryption(char* filename1, char* filename2)
file1.open(filename1, ios::in | ios::out | ios::binary);
cout << "ERROR: Cannot find file with the name of " << filename1 << "!" << endl;
badfilename = true;
//encrypts the file
int index = 0;
//sets the pointers to the beginning of the file
file1.seekg (0, ios::beg);
file2.seekp (0, ios::beg);
//reads the first value
//loop for four bits
for(int c = 0; c < 4; c++)
//finds out if the first bit is a one
currentBit = (int)((unsigned char)currentByte / 128);
//shifts the byte over
currentByte <<= 1;
//if the first bit was a one then we add it to the end
currentByte += 1;
//writes the character
//increments the pointer
//reads the next value
//closes both of the files
int main( void )
char name1; //IS THERE A WAY TO HAVE A VARIABLE LENGTH ARRAY?!!!!!!
cout << "***ENCRYPTION PROGRAM***" << endl;
cout << "Please enter the file name (including the extension):" << endl;
cout << endl;
Encryption delta(name1, "output1.txt");
delta.Encrypt();//Encrypt the file
delta.close();//Close the file
Encryption gamma("output1.txt", "output2.txt");
gamma.Encrypt();//Decrypt (by re-encrypting) output1.txt which is the encrypted version of the orignal file
delta.close();//Again, close it.
cout << "Succesfully encrypted file! \"output1.txt\" contains the encrypted data." << endl; //Happpy
cout << "Error opening file. Could not encrypt!" << endl;//Depressing
If not, is there another more advanced data storage type?
Any and all help is appreciated!