Construct a C program that can read in data values (representing three poster-li
ID: 3633502 • Letter: C
Question
Construct a C program that can read in data values (representing three poster-like images) from a file and print them outas described below. Your program should:
a) be able to open and read a text file that contains the integer data describing the images (the data is identified and contained within braces
in the same format as would be used to define a two-dimensional array within a C program and each data item is simply
an integer between 0 and 4 inclusive, so the images will be somewhat crude -- see above example); The text file is: text.txt. So your
program will have to read past the initial characters (such as "int washingtonImage[58][60] =" ) and curly braces, etc.
to get to the integer values themselves. You may find some of the code that you developed in Assignment #3 to be helpful.
b) be able to process and print a character (representing each of the values appearing in the input file) according to the following: a black pixel
is indicated by the integer value 4 in the data and is printed using the blank character (an ASCII value of 32), dark gray
(indicated by integer value 3) is printed using the character with ASCII value 176, gray (indicated by value 2) is printed
using the character with ASCII value 177, light gray (indicated by value 1) is printed using the character with ASCII
value178, and white (indicated by value 0) is printed using the character with ASCII value 219;
c) contain (at least) two functions -- one that reads in the data from the text file and another that prints each image
from the data once it has been read in (followed by one line of dashes to separate each image from the next,
e.g. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -);
Explanation / Answer
C program that can read and write data to FSL.
#include "xparameters.h"
#include "mb_interface.h"
#include "xbasic_types.h"
#include "stdio.h"
#include "xutil.h"
//====================================================
int main (void) {
print("-- Entering main() -- ");
int i;
Xuint32 arr[64];
for(i=0;i<64;i=i+1){
putfsl(i,0);
}
for(i=0;i<64;i=i+1){
getfsl(arr[i],0);
}
for(i=0;i<64;i=i+1)
xil_printf(" 0x%x",arr[i]);
print("-- Exiting main() -- ");
return 0;
}
#include "xparameters.h"#include "mb_interface.h"#include "xbasic_types.h"#include "stdio.h"
#include "xutil.h"
//====================================================
int main (void) {
print("-- Entering main() -- ");
int i; Xuint32 arr[64]; for(i=0;i<64;i=i+1){ putfsl(i,0); }
for(i=0;i<64;i=i+1){ getfsl(arr[i],0); } for(i=0;i<64;i=i+1) xil_printf(" 0x%x",arr[i]); print("-- Exiting main() -- "); return 0;}
end here
******************************************************************************************************************************
*************************************************************************************************************************