How to write a struct to a file using fwrite?

后端 未结 6 989
你的背包
你的背包 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条回答
  •  -上瘾入骨i
    2021-01-21 09:31

     // i tried to use storedVal.key[0] = k1[0]; but i was getting compile errors
    

    For this one. storedVal is a pointer to the struct. C's pointer dereference operator is -> so you want

     storedVal->key[0] = k[0];
    

提交回复
热议问题