Problem in Encryption / Decryption

I'm trying to implement simple symmetric key cryptography algorithm. In which provided a key and message stream it just XORs the character of key and message one by one and encrypts them and similarly for decryption.
In my code while reading the file, after the all characters are read from the file provided as input an extra last character is read (this is before EOF as I've used while(fp) //fp is the file stream to detect EOF) which gets XOR with the key element.
Because of this when I decrypt using the same logic the extra character again gets XOR and gives me a junk character at the end of the message.
How do I remove this last character from getting XORed?