How to write a struct to a file using fwrite?

后端 未结 6 993
你的背包
你的背包 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

    You are using sizeof on a pointer, this won't calculate the size of the effective struct but the one of the pointer (that could be 4 or 8 bytes). Try with sizeof(struct keyEncode) (sizeof(keyEncode) is enough if you are using C++).

    Then I don't get why you have 0xFFFF as count, shouldn't it be just 1?

提交回复
热议问题