home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / hp / 9212 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.4 KB  |  56 lines

  1. Xref: sparky comp.sys.hp:9212 comp.sys.sgi:12306
  2. Path: sparky!uunet!stanford.edu!rutgers!igor.rutgers.edu!paul.rutgers.edu!slu
  3. From: slu@paul.rutgers.edu (shen lu)
  4. Newsgroups: comp.sys.hp,comp.sys.sgi
  5. Subject: Help for my binary read !!!
  6. Keywords: binary file read
  7. Message-ID: <Aug.12.15.40.21.1992.3094@paul.rutgers.edu>
  8. Date: 12 Aug 92 19:40:22 GMT
  9. Followup-To: comp.sys.sgi
  10. Distribution: usa
  11. Organization: Rutgers Univ., New Brunswick, N.J.
  12. Lines: 42
  13.  
  14. B
  15. Dear netters:
  16.    I have the following c-code which reads in a binary file
  17.    generated by Fortran program write: write(10) n1,n2,n3,n4
  18.    (Here, n1=40,n2=60, n3=17, n4=1)
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. main()
  24. {
  25.   int n_rows, n_cols, n_layers, n_systems;
  26.   int  buff[4];
  27.   FILE *fp10;
  28.   if( (fp10=fopen("RCAF10", "r"))== NULL) {
  29.       printf("cannot open file \n");
  30.       exit(1);
  31.      }
  32.  
  33.       fread(buff,sizeof(int),4,fp10);
  34.       n_rows = buff[0];
  35.       n_cols = buff[1];
  36.       n_layers=buff[2];
  37.       n_systems=buff[3];
  38.      printf("%d %d %d %d\n", n_rows, n_cols,n_layers, n_systems);
  39. }
  40.  
  41.  
  42.  Interestingly, the c-code will give me the following results:
  43.      16 40 60 17  
  44.      ^^
  45.      (What's is 16 doing here ? )
  46.  
  47.  I then wrote a fortran read-in program to read in the 4 numbers, 
  48.  the results is fine:
  49.       40 60 17 1
  50.  
  51.  What's going on ?
  52.   I tested both code on SGI IRIS and HP 835 machines, they give the 
  53.   same unmatching results.
  54.  
  55.  Could somebody out there give me some hint ?
  56.