Write a program to create a binary file, C/C++ Programming

Assignment Help:

  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);
  }


Related Discussions:- Write a program to create a binary file

Html, world wide web commands

world wide web commands

Text Editor, Add a function for saving the text stored in an array to a fil...

Add a function for saving the text stored in an array to a file. Your program must check whether or not the output file already exists, and if it does, your program must ask the us

Program, fine the class bankAccount to implement the basic properties of a ...

fine the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder''s name (string), account nu

Variables within c, Within software languages we have the ability to store ...

Within software languages we have the ability to store information in mail boxes i.e. memory slots which are given names to represent the box. The naming rules are governed by the

Singly linked list, For this program you will add and test 2 new member fun...

For this program you will add and test 2 new member functions to the IntSLList class posted on the website. The two member functions are: insertByPosn(int el, int pos) Assuming t

Write a structured and annotated c program, Intelligent homes are becoming ...

Intelligent homes are becoming increasingly popular as the cost/performance ratio of microcontrollers is continuously dropping.  These systems incorporate various transducers to de

C program for bubble sort, C program for bubble sort: void main() {...

C program for bubble sort: void main() { int i,j,k,a[10],n; clrscr(); printf("How many values you want to enter\n"); scanf("%d",&n);  for(i=0;i  {  pri

C, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of the c

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd