Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need C codes for linux platform. only for #3 question. Ive attached #2 solution. just provide #3 solutions please. 3. Repeat part 2 (by

I need C codes for linux platform. only for #3 question. Ive attached #2 solution. just provide #3 solutions please.
image text in transcribed
image text in transcribed
3. Repeat part 2 (by writing a new C program) as per the following procedure (a) Read the next 100 characters from source.txt, and among characters read, replace each char- acter '1' with character 'A' 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 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) 10:46 Here is the solution for 2. ./cpsim source file dest file cpsim.c include include include cfentl.h> include define BUFF SIZE 1024 int mainint arge, char argv[]) int srcFD destFD nbread nbwrite; char "buff[BUFF SIZE): // Check if both source and destination file names are provided or not if(arge != 3) printf(" Please provide source and destination file names as command line arguments. Eg., cpsim source destination"); exit(EXIT_FAILURE); // open source file in read only mode srcFD = open(argv[1], O_RDONLY): if(srcFD -1 printf(" Error opening file %s erro Kdn", argv errno): exit(EXIT FAILURE): // open destination file in write only mode. Truncate if already existing or create if not available destFD = open(argv[2].0 WRONLY TO_CREAT O TRUNC); if(destFD -1) printf(" Error opening file %s erro = %d ",argv[2], errno): exit EXIT FAILURE): Il copy contents of source file to destination file. while inbread read(srcFD, buff BUFF SIZE)) > if(write(destFD buft nbread) I= nbread) printf(" Error in writing data to Ks ",argv[2]): ifnbread -1) printf(" Error in reading data from sin" argv[1]): if(close(srcFD) == -1) printf(" Error in closing file%s "argv[1]): if(close(destFD) == -1) printf(" Error in closing file %s ", argv[2]); exit(EXIT_SUCCESS)

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

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

What are the uses of performance appraisal?

Answered: 1 week ago