Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that will: Read the first 4 bytes of a .bin file. These bytes

ID: 3806868 • Letter: W

Question

Write a C program that will:

Read the first 4 bytes of a .bin file. These bytes contain a number stored in Little Endian format. This is to be passed back to the variable which is pointed to by num. Print the result, num, in decimal format. The next 8num bytes of data are an array of num floating point numbers. These are stored as 8 byte double precision. Allocate memory to store these floating point numbers using malloc(), and pass back a pointer to the floating point numbers, pointed to by val. Print out the results. Return 0 if successful, -1 otherwise.

As the file is in binary, you MUST use fopen("file", "rb") and fread().

FUNCTION PROTOTYPE MUST BE IN FORMAT: int read(int *num, double *val[], char *file)

(Note that *val[] is equivalent to **val)

Thank you!

Explanation / Answer

first we have to know about little endian and big endian formats.

ex: address= ox 02468ABC

big endian: 02468ABC

little endian: BC8A4602

4 byte address we divide it into byte by byte and apply little endian in reverse order of byte.

C program to read a binary file:

we read first 12 bytes of data and these 12 bytes of data is consists of 2 types

first 4 bytes are in little endian

next 8 bytes are floating point numbers..

float *fnum=8*malloc(sizeof(float));

fnum=float;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote