Project Overview The world operates from lefttoright When re

Project Overview: The world operates from left-to-right. When reading and writing, everything flows from left-toright, and top-to-bottom, on a page. However, it does not have to be that way. This program takes a file of text and prints the file from right-to-left (rather than the normal left-to-right). This is a form of mirror writing (think Leonardo da Vinci). We’ll still go from top-to-bottom with the output, but each line is now written right-to-left.
The name of the input text file, as well as a formatting code for the output, is given on the command-line. The best way to understand this project is by looking at a few examples. The bottom row of the table, the green numbers, is simply to help identify column spacing in the output.

Example:

./mirror test.dat L15

nworb kciuq ehT

revo depmuj xof

dlo yzal eht

.god

123456789012345

All input for this program is given on the command line. If the user does not specify the correct number of command-line arguments, print an error message and exit. The two command-line arguments will always be in the order shown above – input file name and format code. If the input file does not exist, or the output column width is not a positive integer, or the justification is not one of left or right or center, then print an error message and exit the program. The format code is a single capital letter (L or C or R) followed by an integer representing the width of the lines. If a C is specified and the number of spaces to add to the line is an odd number, you can insert the additional space either before or after the text. For example, if you had a line length of 20 and 17 actual characters of text, then you could have 2 spaces before and 1 after or 1 space before and 2 after. The specified output column width will always be at least as large as the longest word in the input file.
For this program, you are reading from an input file – read one token/word/string at a time. If the token that you just read fits on the current output line, add it to the output line. If it does not fit (the output line would be too long), then print the existing output line and add the token as the first word on your next line of output.

What You Need To Do Create a directory project4 on your machine. In that directory, create a file named mirror.c In mirror.c, write the code needed to format text from the specified input file according to the width and justification provided. Make sure that your program: o Has a header block of comments that includes your name and a brief overview of the program. o Has at least two inline comments. o Uses at least three functions, and these functions have function signatures at the top of your file.

*Currently struggling to do this project. I know to work it out with something like the following for a brief example:

#Include <stdio.h>

//comment block

void function signature

void function signature

void function signature

int main() {

-Error statements using If and else

followed by three different void functions to jusitfy left, center, then right.

Then another function for reversing the output code, unless it is suppose to be in the main? Not entirely sure.

Solution

char *str;
// declare an integer variable for length of string
int lenghtstr;
// get the string
printf(\"Enter a string: \"); gets(str);

clrscr(); // clears the screen

// get the lenght of the string and display at the center
lengthstr = strlen(str);
/* set the cursor to the approximate center of a screen
considering that a screen is 80 char wide by 40 char height */
// 1 - 80 from left to right and 1 - 40 from top to bottom
gotoxy(40 - (lengthstr/2), 1);
// display the text at cursor position
printf(\"%s\", str);

char *str;
// declare an integer variable for length of string
int lenghtstr;
// get the string
printf(\"Enter a string: \"); gets(str);

clrscr(); // clears the screen

// get the lenght of the string and display at the center
lengthstr = strlen(str);
/* set the cursor to the approximate center of a screen
considering that a screen is 80 char wide by 40 char height */
// 1 - 80 from left to right and 1 - 40 from top to bottom
gotoxy((lengthstr/2), 1);
// display the text at cursor position, left justified
printf(\"%s\", str);

}

public void rightjustify()

{

char *str;
// declare an integer variable for length of string
int lenghtstr;
// get the string
printf(\"Enter a string: \"); gets(str);

clrscr(); // clears the screen

// get the lenght of the string and display at the center
lengthstr = strlen(str);
/* set the cursor to the approximate center of a screen
considering that a screen is 80 char wide by 40 char height */
// 1 - 80 from left to right and 1 - 40 from top to bottom
gotoxy(40- (lengthstr/2), 80);
// display the text at cursor position
printf(\"%s\", str);

} // Please try the code for reversing contents of the file and justification , here i took a string and printed according to left, right or center justified on the screen .

Project Overview: The world operates from left-to-right. When reading and writing, everything flows from left-toright, and top-to-bottom, on a page. However, it
Project Overview: The world operates from left-to-right. When reading and writing, everything flows from left-toright, and top-to-bottom, on a page. However, it

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site