3. 120 pts.) Fill in the space below each single line comment with the correct i
ID: 3881982 • Letter: 3
Question
3. 120 pts.) Fill in the space below each single line comment with the correct information Il List all necessary includes (you wil most likely add as you read the directives ve void main(void) Il Correctly declare two file object pointers named: in 1 and outl: given belowl. I/ Declare two arrays of char, a 1 dimension of 54 bytes and a 2 dimension (160 x 480) of bytes: of the correct number // Open a binary file named input.x for input and assign the returned value to in·as declared above // Open a binary file named output.x for output and assign the returned alue tout,J as decdared bove // Read 54 bytes from input.x into the 1 dimensional array using the variable declared above: // Fill the 2D array by continuing to correctly read from input.xc // Write all necessary statements to properly clean up for conclude) what some of the pevius satinao //have done: // Write all necessary code to send all the data contained in the 2D array to outputxExplanation / Answer
// Necessary include file to compile programe
#include<stdio.h>
int main()
{
// declaring file pointer
FILE* in_1;
FILE* out_1;
int i;
// declaring 1-D array a1 and 2-D arrray a2
char a1[54],a2[160][480];
// opening file in read binary mode
in_1 = fopen("input.x","rb");
//opeining file in write binary mode
out_1 = fopen("output.x","wb");
// read 1-D array freom in_1 read file pointer
fread(a1,54,1,in_1);
// read 2-D array from file input.x
// iterating 160 times and reading 480 byte in single iteration
for( i = 0; i < 160; ++i)
fread(a2[i],480,1,in_1);
// write 2-D array to file output.x
// iterating 160 times and reading 480 byte in single iteration
for( i = 0; i < 160; ++i)
fwrite(a2[i],480,1,out_1);
}
// NOTE: Creat file input.x and put some randome data in it
// compile code and verify output.x is same as input.x
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.