Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Reading a binary data file and printing it out output file input file struct description This is my code so far: #include #include #include #include

Reading a binary data file and printing it out

imageimage

image

output fileimage

input file

image

struct description

image

This is my code so far:

#include

#include

#include

#include

struct record{ // declare the variables // do nottouch float aunt; short mist; bool drop; short women; char chess; double language; bool cover; bool circle; unsigned char clam; unsigned int current; long int elbow; float zephyr; short int reason; unsigned char bridge; char minute[7]; long int twist;};

int main(int argc, char **argv){

FILE *f;

struct record rec1;

fopen(argv[1], "rb");

fread(&rec1, sizeof(argv[1]), sizeof(argv[1]), f);

if (f == NULL){

fprintf(stderr, "%s doesn't exist!", argv[1]);

exit(1);}

if (!f){

printf( "Usage: %s inputfile", argv[1]);

exit(1);}

fclose(f);

printf("aunt, mist, drop, women, chess, language, cover, circle,clam, current, elbow, zephyr, reason, bridge, minute,twist");

printf("%f,%hi,%d,%hi,%c,%f,%d,%d,%u,%u,%ld,%f,%u,%u,%s,%ld",rec1.aunt,rec1.mist, rec1.drop, rec1.women, rec1.chess, rec1.language,rec1.cover, rec1.circle, rec1.clam, rec1.current,rec1.elbow,rec1.zephyr, rec1.reason, rec1.bridge, rec1.minute,rec1.twist);

return 0;

}

--Please assist in code if any mistakes

--Please explain how to execute in command propt.

please help in completing code

Stage 2: Reading a binary data file and printing it out [3 marks] In this stage you will read a binary data file in a known format, storing the information into instances of a C data structure which you will then print out. This stage develops the following specific skills: Reading binary data Opening and closing files Printing various data types using printf. Using a simple command-line parameter. Resources filestruct-description.txt: Describes the members of the C data struct which correspond to fields in the records of the data file. input-*.bin: Sample binary input files. output-*.txt: Sample text output files corresponding to the input files. Useful Unix commands You might find the following Unix system commands helpful. "more" or "less" diff od

Step by Step Solution

3.56 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

Solution for the ab... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions