Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. The cp command copies the source file specified by the SourceFile parameter to the destination file specified by the DestinationFile parameter. Write a C

1. The cp command copies the source file specified by the SourceFile parameter to the destination file specified by the DestinationFile parameter.

Write a C program that mimics the cp command using open() system call to open source.txt file in read-only mode and copy the contents of it to destination.txt using read() and write() system calls.

image text in transcribed

2. Repeat part 1 by writing a new C program) as per the following procedure:

(a) Read 100 characters from source.txt at a time, and among characters read, replace each character `1` with character `L` and all characters are then written in destination.txt (

b) Write characters "XYZ" into file destination.txt

(c) Repeat the previous steps until the end of file source.txt. The last read step may not have 100 characters.

General Instructions Use errorno/perror sub-routine to display meaningful error messages in case of system call failures. Properly close the files using close system call after you finish read/write. Learn to use man pages to know more about file management system calls (e.g, man read).

An example to open and create file: \#include \#include \#include int main(int argc, char* argv[]){ int fd; if (argcI=2){ printf("File parameter is missing ); return 1 ; \} errno =0; fd= open (argv [1], 0_CREAT 0_RDWR, S_IRUSR|S_IWUSR|S_IRGRP S_IWGRPS IROTH); if (fd==1){ printf(" open () failed with error [\%s] n ", strerror(errno)); return 1; \} else \{ printf(" Open() successful ); / open() succeeded, now one can do read operations on the file since we opened it in read-only mode. Also once done with processing, file needs to be close */ \} close(fd); return ; \} The code above gives a basic usage of the open( function. Now, lets run the code and see the output: $./ open sample.txt Open() Successful

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_2

Step: 3

blur-text-image_3

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

=+from: a) a MNEs perspective? and b) the HRM managers perspective?

Answered: 1 week ago