Why doesn't fwrite() write a Binary File using “wb”, in C, on Mac OS X?

后端 未结 6 1396
鱼传尺愫
鱼传尺愫 2020-12-20 21:15

For the sake of learning C and understanding the difference between Binary Files and Text Files, I\'m attempting to write a string to file as both file types like so:

<
6条回答
  •  天命终不由人
    2020-12-20 21:45

    Unix like OS treats both as same. I'm not sure this is the right answer, but if you want to put a text as hex into a file, try applying \x before the text.e.g. if you are trying to write hello into a file, you're buffer will be:
    char *buf = "hello";
    If you want to write hex of "hello" into the file, your buffer should be like this
    char *buff = "\x68\x65\x6c\x6c\x6f";
    Hope it helped

提交回复
热议问题