Question
Write a function using C that draws a line following coordinates. You have to write your main function that interacts with files (descriptions to follow).
Write a function using C that draws a line following coordinates. You have to write your main function that interacts with files (descriptions to follow).
You are given an input file which contains a set of (x, y) coordinates. These coordinates are written, so that a line segment is connected from the coordinate in the preceding line to the coordinate. For example, lets assume that input.txt contains the following coordinates: >> cat input.txt 0,0 0,1 1,1 1,0 0,0
The first coordinate is at coordinate 0,0 and the next coordinate is at 0,1. There is a line segment of a length 1 from 0,0 to 0,1 in the xy plane. The next line segment moves from 0,1 to 1,1 with a length of 1. This continues until line #5 is processed. In your output file (descriptions to follow), the line segments are represented by a sequence of *s. From the previous input file, the output file will contain the following:
>>cat output.txt ** **
Lets take a look at another example where we are drawing a rectangle this time.
>> cat input.txt 0,0 0,4 2,4 2,0 0,0 >> cat output.txt *** * * * * * * *** Finally, your input and output can be the following as well. >> cat input.txt 2,2 4,0
0,0 2,2
>> cat output.txt * * * ***** Our program will read an input from a file and write an output to a file. There will not be any output to the console. In order to read/write from/to a file, we need to use file I/O libraries.
Detailed specifications are below. 1. The command line argument is in this order
Restrictions As you might have noticed, the size of your shape differs depending on your input. You are not allowed to use [] anywhere in your code except when you are passing command line arguments. This means argv[x] is the only place where you can use []. You can use argv[1] and argv[2] only once. You must use malloc or a variant of malloc to allocate necessary memory. You are not allowed to allocate arbitrarily large array. In our triangle example, the malloc is supposed to only allocate 15B. Your malloc must be the smallest to be able to draw the shape. Your draw does not need to start from 0,0. Any malloc that uses extra space will get automatic 50% penalty in the overall grade.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started