Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Linux #include #include #include #include #include int main(){ int x1, x2, y; char buf[50]; x1= open(hw9-2.c, O_RDONLY,00777); x2= open(cphw9-2.c, O_RDWR | O_CREAT | O_RDONLY,00777);

In Linux

#include #include #include #include #include

int main(){ int x1, x2, y; char buf[50];

x1= open("hw9-2.c", O_RDONLY,00777); x2= open("cphw9-2.c", O_RDWR | O_CREAT | O_RDONLY,00777); for(;;){ y = read(x1,buf,20); if (y==0) break; write(x2, buf, y); } return 0; }

But, get the name of the files from the user like this

:

Enter src file name

hw9-2.c

Enter dest file name

newhw9-2.c

hw9-2.c is copied into newhw9-2.c successfully.

and

1) Write "mycat" that displays the contents of a user-input file in the terminal as characters. Give a text file and a non-text file to mycat and explain the difference.

$./mycat

Enter file name

f1

The content of f1 is :

I have a dream

that one day this nation

will rise up and

live out the true

meaning of its creed

that all men are created equal.

$./mycat

Enter file name

hw9-2

.............

2) Write "myxxd" that displays the contents of a user-input file in the terminal in hexadecimal numbers. Give a text file and a non-text file to myxxd and explain the difference. You need to use printf(%x , buf[i]) to display a byte in a hexadecimal number. Also declare the buffer as an array of unsigned char.

$./myxxd

Enter file name

f1

The content of f1 is :

49 20 68 61 ..........

$./myxxd

Enter file name

hw9-2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago