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 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)