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];
unsigned short encoded[2];
};
I then declare my struct and a pointer to that struct in my main:
struct keyEncode keynEncode;
struct keyEncode *storedVal = &keynEncode;
I then assign values to the struct and want to write the struct to a file using fwrite:
keynEncode.key[0] = k1[0];
keynEncode.key[1] = k1[1];
keynEncode.encoded[0] = p[0];
keynEncode.encoded[1] = p[1];
// i tried to use storedVal.key[0] = k1[0]; but i was getting compile errors
fwrite(storedVal, sizeof(storedVal), 0xffff, fp);
Now my problem is that fwrite writes nothing to the file.
Where am I going wrong?