Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include int main(void) { FILE * binFile_charType; binFile_charType = fopen(binFile_charType.bin, w); FILE * binFile_intType; binFile_intType = fopen(binFile_intType.exe, w); FILE * binFile_shortType; binFile_shortType =

#include  #include  #include  int main(void) { FILE * binFile_charType; binFile_charType = fopen("binFile_charType.bin", "w"); FILE * binFile_intType; binFile_intType = fopen("binFile_intType.exe", "w"); FILE * binFile_shortType; binFile_shortType = fopen("binFile_shortType.what", "w"); FILE * binFile_mixedType; binFile_mixedType = fopen("binFile_mixedType.mix", "w"); //Write char type message to bin file char * msg = "Hello world!"; fwrite(msg, sizeof(char), strlen(msg), binFile_charType); //Write int type values to bin file int intArray[] = {0,1,2,3,4,5}; fwrite(intArray, sizeof(int), 6, binFile_intType); //Write short type values to bin file short shortArray[] = {48,49,50,51,52,53}; fwrite(shortArray, sizeof(short), 6, binFile_shortType); //Write mixed type values to bin file int intVal = 2; float floatVal = 0.0f; double doubleVal = 1.0; char charVal = 'Y'; short shortVal = 10; fwrite(&intVal, sizeof(int), 1, binFile_mixedType); fwrite(&floatVal, sizeof(float), 1, binFile_mixedType); fwrite(&doubleVal, sizeof(double), 1, binFile_mixedType); fwrite(&charVal, sizeof(char), 1, binFile_mixedType); fwrite(&shortVal, sizeof(short), 1, binFile_mixedType); //What would you see in those files if you viewed them in text editor? //close the file streams ---skipping for now. Add later return EXIT_SUCCESS; }

8C - Writing Data to Binary File

Part A. What-you-see may not be what-it-is

Run the given program FileWriting_BinaryFile.c which will create four different binary files. View the binary files created by the program using a text editor. Write down the values written by the program and what you see in each file viewed by a text editor. Explain why the contents you see in the files are the same or not the same as the values written by the program.

Values written by the program

Contents you see in the file

Why

binFile_charType.bin

Hello World!

Hello World!

binFile_intType.exe

0,1,2,3,4,5

NUL NUL

binFile_shortType.what

48,49,50,51,52,53

012345

Those are asking code values of program.

binFile_mixedType.mix

?Y

Response to the questions based on the code block

FILE * binFile_mixedType;

binFile_mixedType = fopen("binFile_mixedType.mix", "w");

//Write mixed type values to bin file

int intVal = 2; //4 bytes

float floatVal = 0.0f; //4 bytes

double doubleVal = 1.0; //8 bytes

char charVal = 'Y'; //1 byte

short shortVal = 10; //2 bytes

fwrite(&intVal, sizeof(int), 1, binFile_mixedType);

fwrite(&floatVal, sizeof(float), 1, binFile_mixedType);

fwrite(&doubleVal, sizeof(double), 1, binFile_mixedType);

fwrite(&charVal, sizeof(char), 1, binFile_mixedType);

fwrite(&shortVal, sizeof(short), 1, binFile_mixedType);

  1. Let each cell in the table below hold one bit. Write down the bit sequence of the file written by the code block.

Hint: Look for the fwrite function to find the values written. Convert the value to binary and fill in the cells below.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

5. Who should facilitate the focus group?

Answered: 1 week ago