Issue to write a value 10 using fwrite
-
Hi , i have an interger x=10; i want to write this by assigning it to const unsigned char variable. whenever i tried to write in file it increase the file offset by 2. for e.g if before writing file offset was 152 after writing it become 154. But i wrote 9 or 11 or any other number than 10 ,it increase offset by 1 means offset increase from 152 to 153. it works fine on Linux but giving issue on windows. Regards, Sachin
-
Hi , i have an interger x=10; i want to write this by assigning it to const unsigned char variable. whenever i tried to write in file it increase the file offset by 2. for e.g if before writing file offset was 152 after writing it become 154. But i wrote 9 or 11 or any other number than 10 ,it increase offset by 1 means offset increase from 152 to 153. it works fine on Linux but giving issue on windows. Regards, Sachin
The value 10 in binary means a new line character. In Windows, a new line is converted to a new line / carriage return character pair. Linux and Unix do not do this. Thats the reason for this behavior.
«_Superman_» _I love work. It gives me something to do between weekends.
-
The value 10 in binary means a new line character. In Windows, a new line is converted to a new line / carriage return character pair. Linux and Unix do not do this. Thats the reason for this behavior.
«_Superman_» _I love work. It gives me something to do between weekends.
Thanks Santosh for quick reply , Can you please help me to write a value 10 in a file .I have an integer with value 10.I do typecasting to store in unsigned char which i pass in fwrite() as parameter. If in windows writing 10 to file treat as different operation as mentioned above, Can you please suggest me alternate way to write value 10 in file i.e. in which format I should pass parameter to fwrite() Regards, Sachin
-
The value 10 in binary means a new line character. In Windows, a new line is converted to a new line / carriage return character pair. Linux and Unix do not do this. Thats the reason for this behavior.
«_Superman_» _I love work. It gives me something to do between weekends.
-
Thanks once again Santosh. I got the issue,Actually i was creating file in 'w' mode instead of 'wb'. with 'wb' mode ,it is working fine. Thanks, Sachin
If it ain't text, don't pretend it is text; use binary mode instead. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.