How to make binary data portable?



Hi,

I write the content of a in file "data" (in Sun Machine). Then I read
"data" in both SunOS and linux. But the result is different. Do you
know how to make it binary data portable.

Best wishes,
Peng


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){

int a = 100;
int b;

FILE *fp;
/* fp = fopen("data", "w");
fwrite(&a, sizeof(int), 1, fp);
fclose(fp);
*/

fp = fopen("data", "r");
fread(&b, sizeof(int), 1, fp);
fclose(fp);

printf("b = %x\n", *((unsigned int*)&b));


return 0;
}

.



Relevant Pages

  • Re: difference in time between sun and linux
    ... i have a file which contains the time and is generated on sun machine. ... i have to decode the time on linux machine. ... int main ... environment issue (timezone, daylight savings, etc). ...
    (comp.lang.c)
  • Re: difference in time between sun and linux
    ... i have a file which contains the time and is generated on sun machine. ... i have to decode the time on linux machine. ... int main ...
    (comp.lang.c)
  • difference in time between sun and linux
    ... i have a file which contains the time and is generated on sun machine. ... i have to decode the time on linux machine. ... int main ...
    (comp.lang.c)
  • [Full-disclosure] Dropbear SSH server Denial of Service
    ... Dropbear SSH server Denial of Service ... Dropbear is a relatively small SSH 2 server and client. ... LEAF Bering uClibc - a small Linux firewall/network applicance ... int max_unauth_clients; ...
    (Full-Disclosure)
  • Dropbear SSH server Denial of Service
    ... Dropbear SSH server Denial of Service ... Dropbear is a relatively small SSH 2 server and client. ... LEAF Bering uClibc - a small Linux firewall/network applicance ... int max_unauth_clients; ...
    (Bugtraq)