(30 points) ASCII Art. Checkout the AsciiArt project from your repository.
For this assignment you’ll implement code that reads in a file where each line contains two integers and a character. For example, one line might be:
10,12,$
Your program will build an “ASCII art” picture from the input file. It will do this by treating each line as a row number, a column number, and a character to put in that position. Rather than displaying the picture in the console, your program will write the output to a new file.
Here's an example. Suppose the input file contained the following lines:
0,2,, 0,3,- 0,4,- 0,5,. 1,2,\ 1,5,_ 1,6,\ 1,7,_ 2,2,_ 2,3,\ 2,4,/ 2,5,_ 2,6,| 2,7,_ 2,8,\ 2,9,_ 2,10,_ 2,11,_ 2,12,_ 2,13,. 2,14,' 2,15,\ 3,0,- 3,1,( 3,2,_ 3,3,_ 3,4,_ 3,5,. 3,6,- 3,7,- 3,8,. 3,9,_ 3,10,_ 3,11,_ 3,12,_ 3,13,_ 3,14,( 4,5,\ 4,9,\ 5,6,\ 5,10,\ 6,7,` 6,8,- 6,9,- 6,10,' 7,0,j 7,1,g
The corresponding output file would contain:
,--. \ _\_ _\/_|_\____.'\ -(___.--._____( \ \ \ \ `--' jg
Image from Andreas Freise's ASCI Art Dictionary.
When a user runs your program, they’ll be asked for a base name (a string) from which the input and output filenames will be constructed by adding -coords.txt
and -pic.txt
. For example, if the user enters plane
, the input file will be plane-coords.txt
and the output file will be plane-pic.txt
.
Follow these steps in main.c
to implement the program:
(3 points) Add appropriate comments at the top of the file. Also make sure you add comments within your code as you go, as usual.
#define SIZE
gives the number of rows and the number of columns for your matrix.(10 points) Prompt the user for the base name. Then read in the lines from the corresponding file. For each line read, store the appropriate character in the appropriate location of your matrix.
Note: Any position not specified by the input file should appear as a blank space in your output file.
(10 points) Write out the resulting matrix to the appropriate output file as determined from the base name the user entered.
Note 1: You may find that it simplifies your debugging to just print the matrix to the console, rather than writing to a file at first. Once you are sure that you've solved steps b and c, then you can switch from printing to the console to writing to a file.
Note 2: After your program runs, you may have to right-click the AsciiArt project in the Project Explorer view and choose Refresh to tell Eclipse to display the newly created file. You can then double-click the output file to view its contents.