home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.hp:9212 comp.sys.sgi:12306
- Path: sparky!uunet!stanford.edu!rutgers!igor.rutgers.edu!paul.rutgers.edu!slu
- From: slu@paul.rutgers.edu (shen lu)
- Newsgroups: comp.sys.hp,comp.sys.sgi
- Subject: Help for my binary read !!!
- Keywords: binary file read
- Message-ID: <Aug.12.15.40.21.1992.3094@paul.rutgers.edu>
- Date: 12 Aug 92 19:40:22 GMT
- Followup-To: comp.sys.sgi
- Distribution: usa
- Organization: Rutgers Univ., New Brunswick, N.J.
- Lines: 42
-
- B
- Dear netters:
- I have the following c-code which reads in a binary file
- generated by Fortran program write: write(10) n1,n2,n3,n4
- (Here, n1=40,n2=60, n3=17, n4=1)
-
- #include <stdio.h>
- #include <stdlib.h>
-
- main()
- {
- int n_rows, n_cols, n_layers, n_systems;
- int buff[4];
- FILE *fp10;
- if( (fp10=fopen("RCAF10", "r"))== NULL) {
- printf("cannot open file \n");
- exit(1);
- }
-
- fread(buff,sizeof(int),4,fp10);
- n_rows = buff[0];
- n_cols = buff[1];
- n_layers=buff[2];
- n_systems=buff[3];
- printf("%d %d %d %d\n", n_rows, n_cols,n_layers, n_systems);
- }
-
-
- Interestingly, the c-code will give me the following results:
- 16 40 60 17
- ^^
- (What's is 16 doing here ? )
-
- I then wrote a fortran read-in program to read in the 4 numbers,
- the results is fine:
- 40 60 17 1
-
- What's going on ?
- I tested both code on SGI IRIS and HP 835 machines, they give the
- same unmatching results.
-
- Could somebody out there give me some hint ?
-