Question: 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

Stage 2: Reading a binary data file and printing it out [3marks] In this stage you will read a binary data file in

a known format, storing the information into instances of a C data

output filestructure which you will then print out. This stage develops the following

input file

specific skills: Reading binary data Opening and closing files Printing various data

struct description

types using printf. Using a simple command-line parameter. Resources filestruct-description.txt: Describes the

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

1 Expert Approved Answer
Step: 1 Unlock

Solution for the ab... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!