Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with 'fread' 1

Status
Not open for further replies.

alarcon

Programmer
Sep 3, 2001
3
0
0
DE
This problem just blows my mind:

I write a file with fwrite containing an integer value (binary).
Then I read that value with fread in a different programm. It works fine except for the values 13 and 26!
I have even used a hex editor to check and write the file myself. All is fine. All the numbers are read beatyfully, except 0x0D=13 and 0x1A=26.
I'm totally lost. I've used serveral compilers but it's always the same.

HELP!
 
I think your are using dos or windows os. The problem is there while reading the file. While reading, Open the file in "rb" mode (ie read and binary), use fread to read the value from the file. The ascii value 13 and 26 are escape sequence characters (13 for Enter and 26 for Ctrl Z).

If you open the file in text mode then these characters will be promoted into 2 characters each and will cause problems. In binary mode the character promotion will not occur.
Note : user "wb" mode while writting date into file.

Maniraja S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top