Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- void writeBinaryFile ( char *fileName , char *comment , int numberOfDoubles , double *doubles , int numberOfInts , int *ints )
- {
- FILE *fp ;
- int charArrayLength ;
- charArrayLength=strlen( comment )+1;
- fp=fopen ( fileName , "wb" ) ;
- fwrite(&charArrayLength , sizeof ( int ) , 1 , fp ) ;
- fwrite(&numberOfDoubles , sizeof ( int ) , 1 , fp ) ;
- fwrite( comment , sizeof ( char ) , charArrayLength , fp ) ;
- fwrite( doubles , sizeof ( double ) , numberOfDoubles , fp ) ;
- fwrite(&numberOfInts , sizeof ( int ) , 1 , fp ) ;
- fwrite( ints , sizeof(int) , numberOfInts , fp ) ;
- fclose( fp ) ;
- }
- void readBinaryFile(char *fileName)
- {
- FILE *fp;
- char *ptr;
- double *ptr1;
- int *ptr2;
- ptr=(char*)malloc(sizeof(char)*5);
- ptr1=(double*)malloc(sizeof(double)*6);
- ptr2=(int*)malloc(sizeof(int)*6);
- fp=fopen ( fileName , "rb" ) ;
- fread(ptr,sizeof(char),11,fp);
- while(*ptr!='\0')
- {
- printf("%c",*ptr);
- ptr++;
- }
- fclose(fp);
- }
- int main(void)
- {
- readBinaryFile("FILE.bin");
- printf("\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement