It is possible to write less than 1 byte to a file

前端 未结 4 2043
忘了有多久
忘了有多久 2021-02-19 09:00

As far as I know the smallest unit in C is a byte. Where does this constraint comes from? CPU?

For example, how can I write a nibble or a singl

4条回答
  •  失恋的感觉
    2021-02-19 09:47

    Moreover data is written to files in sectors (e.g. 512 bytes or so). And if we need to change only one byte the whole sector is read, patched and written back.

    But you don't need to thinkabout sectors. To Change one bit just seek to apropriate byte position in file, read that byte, change the bit and write the result back.

提交回复
热议问题