variable sized arrays

Hello experts, I'm new and I have written a program for a class that encrypts a text file using XOR. I have not been able to make it work just right yet. I'm not looking for an answer to my assignment just some direction. Is it possible to create an array that would look at the size of the file? My code is taking the key and trying to XOR it with the entire array that I have alotted. so I end up with the key repeating after it has XORed the text to the eof. Here is a snippet of my code (I don't want to paste the whole thing):

snippet 1:

1
2
3
4
5
6
7
    ifstream infile;
    ofstream outfile;
    string key;
    string filein;
    string fileout;
    char filebuff[256];
    char encbuff[256];


The above piece is my declarations and my array sizes. I am trying to read the file into the "filebuff" array then XOR the characters into the "encbuff" array. I am doing that by:
1
2
3
4
5
6
7
8
{
       infile>>filebuff;                                  
       for(int i=0; i<sizeof(filebuff) ;i++)
             {
              encbuff[i]=filebuff[i]^=keybuff[i%L];
              outfile<<encbuff[i];
             }       
     } 

I think my problem is in my for loop. I think by using i<sizeof(filebuff), it is causing the repeating key? Any suggestions that may help would be appreciated!
Variable Sized Array = Vector see here: http://www.cplusplus.com/reference/stl/vector/

There's a slight learning curve but for stuff like this they are golden.
Topic archived. No new replies allowed.