Quote:
Originally Posted by ocli5568
... for some reason every time i run it, on the 1105th (exactly) iteration, fputc seems to put two bytes into fout, and does so every time the 'c' byte value is 10 after that.
Character code 10 (0x0A, ASCII LF) is commonly used by C as the logical 'newline' character, and is used to delimit lines of text.
By logical newline I mean the character you use in your program; the physical newline is the character(s) actually present in the text file. Different operating systems have different conventions for physical newline. For example, here are the physical newline codes for some common operating systems:
- Windows: the 2-byte sequence 0x0D, 0x0A
- Macintosh: the single byte 0x0D
- UNIX: the single byte 0x0A
The C compiler automatically translates between logical and physical newline for text files for you. It does this for both input and output.
Try opening the input and output files as binary files (refer to the fopen documentation).
By the way, you ought to be trapping error returns from fgetc and fputc. You never know when something might go wrong.