How to make binary data portable?
- From: "PengYu.UT@xxxxxxxxx" <PengYu.UT@xxxxxxxxx>
- Date: 30 Jun 2005 10:14:10 -0700
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;
}
.
- Follow-Ups:
- Re: How to make binary data portable?
- From: Charles Mills
- Re: How to make binary data portable?
- From: Martin Ambuhl
- Re: How to make binary data portable?
- Prev by Date: Re: Microsoft Visual C++ 6.0
- Next by Date: Re: why use -> (not .) with pointers?
- Previous by thread: why use -> (not .) with pointers?
- Next by thread: Re: How to make binary data portable?
- Index(es):
Relevant Pages
|