EOF not working

I'm toying around with some basic encryption, and I'm trying to read a file byte by byte. My code for this is:

1
2
3
while((byte = fgetc(inf)) != EOF) {
	fputc(byte^(argv[3][index++%key_length]), outf);
}


However, when I try to run my program to encrypt a file of roughly 70 kb, ut produces an encrypted file of about 50 bytes, so obviously it is finding EOF before it's supposed to. Anyone know why this is happening?

EDIT: I'm also doing error checking further down the road, and nothing indicates that EOF is caused by any error.
Last edited on
Is byte of type int?
Nope, it's char. Should it be an int?

EDIT: Allright, changing it to int did the trick :) Thanks! It's kinda weird though, because I'm pretty sure I've done it this way using char before...
Last edited on
http://www.cplusplus.com/reference/clibrary/cstdio/fgetc/

This link answers this problem properly. :)
Topic archived. No new replies allowed.