• Forum
  • Lounge
  • Why does copying of content corrupt file

 
Why does copying of content corrupt files?

Hi.

I just made my first encryptor/decryptor program in C++.It can encrypt any text files without any problems at all. However, I wanted to be able to encrypt and decrypt any file type, without corrupting it. Once I tried to open a .jpg file just for fun in notepad. I copied all the content of the file into an empty document. Then I saved it as a new .jpg file. However, this does not work because when I try to open it with the image displaying program, it says that the file is ruined/can not be opened. Why can you not copy the raw data of image files and other files without corrupting them like this?

I have never been an expert when it comes to this topic so please explain what happens.
Because notepad is a text editor. The byte values in the binary file don't exactly all match up to ASCII.

Look up fstream. Read each individual byte and write it to a new file.
So if I treat all files as binary files, I should be able to encrypt/decrypt all files?
And this should be in the beginners forum
CaptainBlast, the reason for why I posted this was that I thought that the beginners forum was only used for specific questions about C++ only. I am sorry.
Well you could. It wouldn't be that hard actually. Since each character is one byte, you can easily just read one byte and copy it, read another, etc.
Ok, I know how to do it now. Thanks for the help. I'm looking forward to solve this :).
Topic archived. No new replies allowed.