Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Issue to write a value 10 using fwrite

Issue to write a value 10 using fwrite

Scheduled Pinned Locked Moved C / C++ / MFC
linuxhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cancerion
    wrote on last edited by
    #1

    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

    _ 1 Reply Last reply
    0
    • C cancerion

      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

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      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.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      C 2 Replies Last reply
      0
      • _ _Superman_

        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.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        C Offline
        C Offline
        cancerion
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • _ _Superman_

          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.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          C Offline
          C Offline
          cancerion
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • C cancerion

            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

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups