Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will write a C program that involves processing 2 - dimensional arrays. A two - dimensional array is often used to
In this assignment, you will write a C program that involves processing dimensional arrays. A twodimensional array is often used to represent a picture or an image For simplicity, your program will process only blackandwhite images. Each pixel in the image will be a single char. The only legal chars are the asterisk which represents the color black, and the blank space which represents the color white. Your program must read the image from stdin. The format of the input file is as follows: the first line of the file will contain two integers followed immediately by a newline. These numbers represent the number of rows and columns in the image, respectively. These dimensions may be any positive int value ie more than digit is possible, such as Each succeeding line will contain one row of the image, followed by a newline char. The newline chars are not part of the image, and should not be included in any of the image processing transformations. For example, the input might be: The size of the image will be at least x You must not make any assumptions about the maximum possible size of an image. If the input file does not have this format, then your program should abort and return an exit status of Note that any additional chars in the input file also constitute an invalid input file. Your C program can abort processing and return to the command line by executing the statement: exit; Your program will need to #include in order to access the exit function. Your program must implement the following image transformations. invert: This transformation should change every into a blank character, and every blank character into a flip direction: This transformation should flip the image. If the direction is either H or h then the image should be flipped across an imaginary vertical line down the center of the image. This transformation is illustrated below for an image of the letter F If the direction is either V or V then the image should be flipped across an imaginary horizontal line across the center of the image. Flip H rotate degrees: This transformation should rotate the image clockwise the specified number of degrees. The only legal values for degrees are and rotate stretch factor: This transformation should stretch the image horizontally by the given multiple. Note that you will need to use dynamically allocated memory to deal with an image that changes its size. stretch The input image to your program must be read from the standard input stdin but the transformations to the image will be specified on the command line. You will invoke the program as follows: $ aout listofdesiredtransformations inputFileName The syntax for the listofdesiredtransformations is as follows: rot indicates a rotation, and must be followed by exactly or flip indicates a flip, and must be followed by a single char, which must be V v H or h inv indicates an inversion stretch indicates a stretch, and must be followed by a single integer value such as or or For example, the program might be invoked as: $ aout rot flip H inv rot stretch flip V inputFileName Note that each entry on the command line is a string of a characters, such as rot or or You can convert a string into an integer using the C library function atoi ascii to integer as shown below. int foobar atoi argv; Your program should perform each of the given transformations, in the given order, and then output the resulting image to stdout. Do not output the image size to stdout. Do not output any intermediate results to stdout. Do not output any other information, such as a message saying Your image now looks like: If your program successfully transforms the image, then it should return an exit status of If the command line arguments are in any way faulty, such as the spelling of the command is incorrect, or the rot is not followed by a legal number of degrees, or the flip is not followed by a legal direction, then your program should abort and return an exit status of This exit status will only be returned if the format of the input file is valid. Notice that it is legal for the command line to contain zero transformations. In this case your program should simply output the original image.
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