Hi all, briefly I am writing a client server app that communicates over shared mem (which is all fine) but I seemed to be stumped on using a union to convert from float to another type. ultimatly what I am trying to achieve is the server writes a 32 bit float to shared memory and the client accesses this and interperets it as an array of boolean chars eg "001101011. ..." I have this rough code that uses a union from float to char[4] (not binary i know but a start) and when I run it the displayed string is different each time?? any ideas?
thanks in advance
thanks in advance
Code:
#include <stdio.h> int main() { union un { float fl; unsigned char str4[4]; } array1; unsigned char temp[4]; array1.fl=1256.667; printf("\n%f Size:%d\n",array1.fl,sizeof(array1.fl)); printf("\n%s Size:%d\n",array1.str4,sizeof(array1.str4)); }
Comment