Write a C program which is called ‘multiple_copy’. This program copies one source file to two destination files as follows:
$./multiple_copy....... source_file....... destination_file1......... destination_file2
multiple_copy program copies the contents of source file (i.e., source_file) to any named two destination files in the command line.
The number of arguments should be 4 including multiple_copy. If the number of arguments is not 4, the program should display error message saying:
“Usage: multiple_copy source_file destination_file1 destination_file2”.
When the source_file does not exist, the program should display error
message with source file name, for example, “Opening Error!: source_file”.
If the destination file exists, existing content of that file should be truncated
(removed).
Hi, Please find the program.
//
// main.c
// CopySourceTo 2 dest Files
//
// Created by Abhirama Gopala Dasa on 16/09/19.
// Copyright © 2019 Abhirama Gopala Dasa. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[]) {
for (int i=0; i<argc; i++) {
printf("%s\n",argv[i]);
}
if(argc!=4){
printf("Please input sourceFile,and 2 destination files\n");
return 0;
}
FILE *source;
FILE *dest1,*dest2;
char data[100];
printf("%s",argv[1]);
source = fopen(argv[1], "r");
dest1 = fopen(argv[2], "w");
dest2 = fopen(argv[3], "w");
if(source==NULL){
printf("Failed to open file");
return 0;
}
while(fgets(data,100,source)!=NULL){
printf("%s",data);
fputs(data, dest1);
// fputs("\n", dest1);
fputs(data,dest2);
// fputs("\n", dest2);
}
fclose(dest1);
fclose(dest2);
printf("\nCopyDone\n");
}
Please make sure the file paths do not contain spaces. thanks. copying is working perfect.
Write a C program which is called ‘multiple_copy’. This program copies one source file to two...
How can I create Loops and Files on Java?
• Create a program that reads a list of names from a source file and writes those names to a CSV file. The source file name and target CSV file name should be requested from the user • The source file can have a variable number of names so your program should be dynamic enough to read as many names as needed • When writing your CSV file, the first row...
Using Unix processes Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README. MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode. ForkCopy.c : Write a...
Write a program that takes a file as input and checks whether or not the content of the file is balanced. In the context of this assignment “balanced” means that your program will check to make sure that for each left bracket there is a closing right bracket. Examples: [ ( ) ] { } à balanced. [ ( ] ) { } à unbalanced. Here is the list of brackets/braces that program must support: (: left parentheses...
write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...
Problem: Write a program that behaves as described below.If the first command-line argument after the program name (argv[1]) is “--help”, print the usage information for the program. If that argument is not “--help”, you are to expectargv[1]and subsequent arguments to be real numbers(C, integer, float, or double types)in formats acceptable to the sscanf()function of the C library or strings of ASCII chars that are not readable as real numbers. You are to read the numbers, count them and calculate the...
C++.Write a program that opens two text files and reads their contents into two separate queues. The program should then determine whether the files are identical by comparing the characters in the queues. When two nonidentical characters are encountered, the program should display a message indicating that the files are not the same. If both queues contain the same set of characters, a message should be displayed indicating that the files are identical. Sample Run Suppose we have two files...
Using Unix processes Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README. MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode. ForkCopy.c : Write a...
Command Line Arguments: Write a program in C Compiler that will accept two integers on command line, subtract the second from the first (1st - 2nd) and display the answer. It exactly two numbers are not provided on command line, there should be a simple error message printed and the program ends with no further input, output, or calculations
Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...
write a c++ code to read multiple integers from input.dat until the end of file. Edit input.dat and put several integers in it. Compile and execute the code then check output.dat to verify all the integers are in there. Update the code to check to see if input.dat exists before reading from it. If it doesn’t exist print an error message (and don’t read!). Compile and execute your code. Delete input.dat and output.dat and execute – did you see your...