How to write a struct to a file using fwrite?

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

    FILE *fp = fopen("c:\\test", "wb");
    if (fp != NULL) {
        fwrite(storedVal, sizeof(keynEncode), 1, fp);
        fclose(fp);
    }
    

提交回复
热议问题