Advertisement
Guest User

Untitled

a guest
Dec 8th, 2012
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. void writeBinaryFile ( char *fileName , char *comment , int numberOfDoubles , double *doubles , int numberOfInts , int *ints )
  5. {
  6.         FILE *fp ;
  7.         int charArrayLength ;
  8.         charArrayLength=strlen( comment )+1;
  9.         fp=fopen ( fileName , "wb" ) ;
  10.         fwrite(&charArrayLength , sizeof ( int ) , 1 , fp ) ;
  11.         fwrite(&numberOfDoubles , sizeof ( int ) , 1 , fp ) ;
  12.         fwrite( comment , sizeof ( char ) , charArrayLength , fp ) ;
  13.         fwrite( doubles , sizeof ( double ) , numberOfDoubles , fp ) ;
  14.         fwrite(&numberOfInts , sizeof ( int ) , 1 , fp ) ;
  15.         fwrite( ints , sizeof(int) , numberOfInts , fp ) ;
  16.         fclose( fp ) ;
  17. }
  18.  
  19. void readBinaryFile(char *fileName)
  20. {
  21.         FILE *fp;
  22.         char *ptr;
  23.         double *ptr1;
  24.         int *ptr2;
  25.         ptr=(char*)malloc(sizeof(char)*5);
  26.         ptr1=(double*)malloc(sizeof(double)*6);
  27.         ptr2=(int*)malloc(sizeof(int)*6);
  28.  
  29.         fp=fopen ( fileName , "rb" ) ;
  30.         fread(ptr,sizeof(char),11,fp);
  31.         while(*ptr!='\0')
  32.         {
  33.             printf("%c",*ptr);
  34.             ptr++;
  35.  
  36.         }
  37.     fclose(fp);
  38. }
  39.  
  40.  
  41. int main(void)
  42. {
  43.     readBinaryFile("FILE.bin");
  44.     printf("\n\n");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement