Question: The original file: #include #include #include #include #include #define LINESIZE 16 //use one command line argument int main(int argc, char *argv[]) { if (argc !=

The original file:

#include

#include

#include

#include

#include

#define LINESIZE 16

//use one command line argument

int main(int argc, char *argv[]) {

if (argc != 2 ) {

printf(\"Usage: diagonal \");

return -1;

}

//create a file so that 16 rows of empty will appear with od -c command

int fd = open(\"diagonal.out\", O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);

char space = ' ';

for(int line=0; line

for(int column=0; column

write(fd, &space, 1);

//Each line of od outputs 16 characters

//So, to make the output diagonal, we will use 0, 17, 34, ....

int n = strlen(argv[1]);

for(int i=0; i

lseek(fd, (LINESIZE+1)*i, SEEK_SET);

write(fd, &argv[1][i], 1);

}

close(fd);

puts(\"diagonal.out has been created. Use od -c diagonal.out to see the contents.\");

}

When we input :

gcc diagonal.c -o diagonal

diagonal Funny!

Output will like below:

Now we need to enhance it to handle any # of words as parameters and output them in a fancy pattern as shown below: Please write this code in C, definitely give the thumbs up, pls don't copy and paste the wrong answer.

Both of these outputs are the result of using the command 'od -c diagonal.out'F n n 0000000 0000020 0000040 0000060 0000100 0000120 0000140 n 0000400 J 0000000 0000020 0000040 0000060 y P o O 0000400 0000420 0000440 0000460 0000500 0000520 0000540 0000560 0000600 0000620 * 0001000 0001020 0001040 0001060 0001100 0001120 0001140 0001160 0001200 0001220 * 0001400 0001420 0001440 0001460 0001500 0001520 0001540 0001560 0001600 U T D 0002000

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!