P
PengYu.UT
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;
}
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;
}