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

Decoding , http://www.expertsmind.com/questions/decodethecode-30110560.aspx...

http://www.expertsmind.com/questions/decodethecode-30110560.aspx

Compute the average of five numbers, Step 1 Define the program headers and ...

Step 1 Define the program headers and the variables      #include   #include   #include   #include void main()   {       char prompt;     float a,b,c,d,e;     floa

C, algo of stack using two queue

algo of stack using two queue

PROGRAMMING, PROCEDUAL PROGRAMMING INTRODUCTION

PROCEDUAL PROGRAMMING INTRODUCTION

C program for function of copy one string in other string, C Program for FU...

C Program for FUNCTION OF COPY ONE STRING IN OTHER STRING #include stdio.h> #include conio.h> int copy(char a[],char b[]); void main() {           char a[100],b[

C Programming, Develop a function to calculate sum of n even integers start...

Develop a function to calculate sum of n even integers starting from a given even integer

A palindrome is a string that reads the same from both the e, submitting so...

submitting solutions in C language should not use functions from / as these files do not exist in gcc

Static optimality theorem, Question 1 Describe the following with respect ...

Question 1 Describe the following with respect to pointers in C language- Pointers and Arrays Usage of Pointers in functions Write programs in C to demonstrate the

Determine the current flowing by resistor, For the circuit shown in Figure,...

For the circuit shown in Figure, verify the p.d. across resistor R3. If the total resistance of the circuit is 100Ω, verify the current flowing by resistor R1. Find also the

Define a complex number in c program, Define a complex number in c program:...

Define a complex number in c program: class complex                                 {                                   private:                                 in

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