Basic Encryption...output file name gets truncated

Hello all at Cplusplus.

I am looking for possible solutions to a code problem in my file encryption source. Can anyone please review and assist. Any CONSTRUCTIVE criticism is welcomed.

The problem is that the output file name is truncated. I am wondering if a null character is going to be the problem somewhere. Any ideas? Additionally, is anything "out of whack" in the encryption routine itself?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
void Chapter13a()
{
   ifstream inFile;
   ofstream outFile;
   char inFileName[81];
   char outFileName[81];
   const int LENGTH = 800;
   char str[LENGTH];
   int count,
       term;
   
   cout << "\nChapter 13 Encrypt a File Output -------\n"
        << "This program uses a simple encryption algorithm to encrypt a file.\n\n";
   cout << "Enter input file name to be encrypted (encryptme.txt): ";
   cin.ignore();
   cin.getline(inFileName,81);
   
   cout << "Enter output file name for encrypted file (encrypted.txt): ";
   cin.ignore();
   cin.getline(outFileName,81);
   
   inFile.open(inFileName-1, ios::in );
   for(count = 0; count < LENGTH; count++)
      inFile >> str[count];
      inFile.close();
    
   replace(str, str+strlen(str), ' ', '$' );
   
   for( int x = 0; x < strlen(str); x++)
    {
        
     str[x] += 2112;
    }
    cout << str;
    ofstream output(outFileName, ios::out);
    for(int i = 0; i < LENGTH; i++)
    {
    output << str[i];
    }
    
   
     
   cout << "The file " << inFileName << " has been encrypted.\n\n\n";
   cout << "Chapter 13 Encrypt a File program terminated successfully!\n"
        << "Enter 1 to exit the Chapter 13 program.";
   cin >> term;                  
}         


Thanks in advance
why don't you just save the filename in a string? that way you don't have to have a limit on it. additionally when calling the ifstream you just appened .c_str()

1
2
3
4
5
6
7
   ifstream inFile;
   ofstream outFile;
   string inFileName;
   string outFileName;

   inFile.open(inFileName.c_str(), ios::in );
   
Topic archived. No new replies allowed.