write a program to create a binary file and


  Write a program to create a binary file and store the following data "hello", 0x0030,'1', 1.234  Using visual studio examine the binary file and note how the day is stored
 
Answer
#include stdio.h
#include stdlib.h
#include string.h
  void main()
    {    
    Version 1.0 
    Function : binary file handling       
     Modifications:   none*/
 
  /* Define I/O streams */

  FILE *fptw;
 
    char prompt;
    char data1[6];
    int data2;
    char data3;
    float data4;
    strcpy(data1,"hello");
    data2 = 0x30;
    data3='1';
    data4 = 1.234;
 
  fptw = fopen("program.txt","wb");
  if (fptw == NULL) 
  {
  /* Check for error */
  printf("Cannot write the file program.txt\n\r");
  exit(1);
  }
  /* Writing binary data in file*/
  fwrite(data1,sizeof(char),strlen(data1),fptw);
  fwrite(&data2,sizeof(int),1,fptw);
  fwrite(&data3,sizeof(char),1,fptw);
  fwrite(&data4,sizeof(float),1,fptw);
  fclose(fptw); 
  printf("Press and key to exit \n\r");
  scanf("\n%c",&prompt);
  }

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: write a program to create a binary file and
Reference No:- TGS0265289

Expected delivery within 24 Hours