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

Car rental project, I need a project on car rental system using c programmi...

I need a project on car rental system using c programming only of college level

COMPILER DESIGN, Compiler Design - Limit In The Method Instructions

Compiler Design - Limit In The Method Instructions

Explain the goto statement, The goto statement This statement can be us...

The goto statement This statement can be used to branch to another statement of the program. This is rarely used as it violates the principle of structured programming. Though

Explain the loop statements in computer programming, Explain the Loop State...

Explain the Loop Statements in Computer Programming? 1. C gives you a choice of three kinds of loop, while, do while and for. 2. The while loop remain repeating an action until

Area under the curve, Write a c++ program to find the area under the curve ...

Write a c++ program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points c

C program for function of merge , C Program for FUNCTION OF MERGE #inc...

C Program for FUNCTION OF MERGE #include conio.h> #include stdio.h> char cot(char a[],char b[]); void main() {           char a[50],b[50];           clrscr()

What are control structures, What are control structures? - Control str...

What are control structures? - Control structures decide which instructions in program must be executed. - This implies that program flow may not necessarily move from one s

Constants, explain about symbolic constants with examples

explain about symbolic constants with examples

Program to calculation of mortgage interest rates, This assignment builds o...

This assignment builds on Homework 3. The two major modifications are the instruction of pointers and the calculation of mortgage interest rates. Requirements for Project 2:

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