1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
char * temp;
const ifstream::pos_type size = 1;
int crypt(string inp, string otp, char key)
{
ifstream inpf(inp.c_str(), ios::in|ios::binary);
ofstream otpf(otp.c_str(), ios::out|ios::binary|ios::app|ios::trunc);
while(!inpf.eof()){
inpf.read(temp, size);
*temp = key ^ *temp;
otpf.write(temp, size);
otpf.flush();
}
inpf.close();
otpf.close();
delete temp;
return 0;
}
|
When tried to do "
*temp = key ^ *temp;
", got "Segmentation fault". What's the matter?
Last edited on
You have to allocate space for temp to point to before you use it.
5 { temp = new char[ size ];
Hope this helps.
[edit]
BTW -- why is temp a global object? Don't do that. ;-)
Last edited on
Thank you very much, it helped!