chibicitiberiu
New Member
Here is the source code:
What it should do is copy a file, but the problem I get is that the copied file has 1 byte more than the source one. In files like mp3s or others this error didn't matter at all, but in .txt files it does. How can I fix it?
Earlier I tried increasing the amount of data stored in the a variable, but it just increased the difference between the original and copied file.
Code:
int copyfile(char* source, char* dest)
{
ifstream input(source, ios::in|ios::binary);
ofstream output(dest, ios::out|ios::binary);
if (!input) return -1;
if (!output) return -2;
char* a;
while(!input.eof()) {
input.read(a, 1);
output.write(a, 1);
}
input.close();
output.close();
return 0;
}
Earlier I tried increasing the amount of data stored in the a variable, but it just increased the difference between the original and copied file.