How to write a struct to a file using fwrite?

后端 未结 6 988
你的背包
你的背包 2021-01-21 09:20

I\'m very new to C, and I am having trouble with fwrite.

I\'m looking to use a struct that holds two values:

struct keyEncode{
    unsigned short key[2];         


        
6条回答
  •  [愿得一人]
    2021-01-21 09:42

    Assuming you only have one such struct, then you need to change:

    fwrite(storedVal, sizeof(storedVal), 0xffff, fp);

    to

    fwrite(storedVal, sizeof(*storedVal), 1, fp);

提交回复
热议问题