Share this post

Link to post

Share on other sites

try adding fputc(EOF, dest) following your while loop. The way you have it set up now you're not writing the EOF character; my guess is the system is saving you by inserting an EOF character when you close the file stream, but puts it one byte too far.

Share this post

Link to post

Share on other sites

Er...No, it doesn''t work. I''ve tried opening the files for wb and rb, and didn''t work. Then I tried also fputc''ing an EOF character at the end. Didn''t work. Tried fputc''ing EOF at the end, without binary mode. Didn''t work.What''s up?

The problem is that feof() doesn't actually test whether you're at the end of the file and there's no more data to read. Instead, feof tests whether an input operation has failed due to there not being any more data to read when you were trying to read it . So what's happening is the last time the loop runs, feof() returns false even though you actually did read all the characters to be read. It doesn't return true until after you've tried and failed to read, and then written that last (invalid) character to the output file.

Share this post

Link to post

Share on other sites

switched argc and argv around, but that''s just a preference thingyou fopen''d the destination twice and only fclose''d it once, so I changed that.Seperated the two fopen commands into seperate if statements, that way if one fails, it can close the open file.

Share this post

Link to post

Share on other sites

quote:Original post by Ecliptici you fopen''d the destination twice and only fclose''d it once, so I changed that.

Look again, the first fopen actually tries to open it read-only to make sure no file is overwritten and success makes the program bail out, so that''s actually OK (except an opened file should be closed before exiting to make it clean).