Help!! can some solve this so i can see what it\'s suppose to look like. Or atle
ID: 3926190 • Letter: H
Question
Help!! can some solve this so i can see what it's suppose to look like. Or atleast help me get started please
CS 100 Project Four
Project Overview: The world operates from left-to-right. When reading and writing, everything flows from left-to- right, 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.
Input file (test.dat) contents: The quick brown fox jumps over the lazy old dog.
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
Input file (test.dat) contents: The quick brown fox jumps over the lazy old dog.
./mirror test.dat L15
nworb kciuq ehT revo spmuj xof dlo yzal eht .god
./mirror test.dat C25
spmuj xof nworb kciuq ehT .god dlo yzal eht revo
./mirror test.dat R20
xof nworb kciuq ehT yzal eht revo spmuj .god dlo
123456789012345
1234567890123456789012345
12345678901234567890
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
void printNormal(char *arr[10], int count){
int i;
for(i=0;i<count;i++){
printf("%s ",arr[i]);
}
}
void printReverse(char *arr[10], int count){
int i;
for(i=count;i>0;i--){
printf("%s ",strrev(arr[i]));
}
}
void printCenter(char *arr[10], int count){
int i;
for(i=count/2;i>0;i--){
printf("%s ",strrev(arr[i]));
}
for(i=((count/2)+1);i<count;i++){
printf("%s ",strrev(arr[i]));
}
}
int main(int argc, char *argv[])
{
char * arr[10];
int count = 0;
if(argc < 3)
{
printf("Arguements are empty.. ");
} else
{
int i = 0;
int temp = 4;
char line [1000];
const char s[2] = " ";
char *tokenVal;
FILE *inputFile;
inputFile = fopen(argv[1], "r");
if(!inputFile)
{
printf("File not opening");
} else
{
printf("Reading file.. ");
//reading lines
fgets(line,sizeof line,inputFile);
// reading each word
tokenVal = strtok(line, s);
for(i =0; (i< temp) && (tokenVal != NULL); i++)
{
int wordlen = strlen(tokenVal);
arr[i] = malloc(wordlen);
strncpy(arr[i], tokenVal, wordlen-1);
count++;
tokenVal = strtok(NULL, s);
}
}
fclose(inputFile);
}
// calling functions
if(argv[2] == 'L'){
printNormal(&arr, count);
}
else if(argv[2] == 'C'){
printCenter(&arr, count);
}
else{
printReverse(&arr,count);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.