1. Complete a function dupFile(const char* name1, const char* name2) in the attached program. template prog.c...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Complete a function "dupFile(const char* name1, const char* name2)" in the attached program. template "prog.c" After its completion, name2 file will have duplicated contents from name1 file contents. For example, if name1 file contains the following 9 characters: ABCDMHJWP Then, after its execution the name2 file will contain 18 characters: ABCDMHJWPABCDMHJWP You can only make use of the following system calls in the function implementation: open() read() Iseek() write) close() You have to complete the function definition in the attached "prog.c" file which includes main() calling dupFile("data1.txt", "data2 txt"). "data1.txt" file is also attached. Your function should use the buffer size of 10 bytes in reading and writing. If you use the other buffer sizes, you will get a penalty of 50% of the entire grade "prog.c* CODE BELOW PLEASE DO NOT CHANGE ANY OF THE CODE UNLESS IT HAS // /* dupFile - dupFile namel name2 */ #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <stdio.h> #include <ctype.h> // !!! DO NOT CHNAGE BUFSIZE #define BUFSIZE 10 #define PERM 0644 /* size of chunk to be read */ /* file permission for new file */ /* dupFile namel name2 */ // name2 file will have duplicated contents from namel file contents int dupFile( const char *namel, const char *name2) { int infile-1, outfile=-1; ssize_t nread, nwrite; char buffer[BUFSIZE]; if( (infile open(namel, O_RDONLY) ) return (-1); == -1) if( ( outfile = open(name2, O_WRONLY O_CREAT | O_TRUNC, PERM) ) == -1) return (-1); // // You need to read the contents of infile and copy to outfile (2 times!) copying! //// } close(infile); close (outfile); return 1; Fill out this part!! - main loop(s) for duplicate int main(int argc, char *argv) { } int main(int argc, char *argv) { if (argc!=3) { printf("Usage: dupFiles file1 file2 \n"); exit(-1); } } int retcode=-1; retcode = dupFile(argv[1], argv[2]); 1. Complete a function "dupFile(const char* name1, const char* name2)" in the attached program. template "prog.c" After its completion, name2 file will have duplicated contents from name1 file contents. For example, if name1 file contains the following 9 characters: ABCDMHJWP Then, after its execution the name2 file will contain 18 characters: ABCDMHJWPABCDMHJWP You can only make use of the following system calls in the function implementation: open() read() Iseek() write) close() You have to complete the function definition in the attached "prog.c" file which includes main() calling dupFile("data1.txt", "data2 txt"). "data1.txt" file is also attached. Your function should use the buffer size of 10 bytes in reading and writing. If you use the other buffer sizes, you will get a penalty of 50% of the entire grade "prog.c* CODE BELOW PLEASE DO NOT CHANGE ANY OF THE CODE UNLESS IT HAS // /* dupFile - dupFile namel name2 */ #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <stdio.h> #include <ctype.h> // !!! DO NOT CHNAGE BUFSIZE #define BUFSIZE 10 #define PERM 0644 /* size of chunk to be read */ /* file permission for new file */ /* dupFile namel name2 */ // name2 file will have duplicated contents from namel file contents int dupFile( const char *namel, const char *name2) { int infile-1, outfile=-1; ssize_t nread, nwrite; char buffer[BUFSIZE]; if( (infile open(namel, O_RDONLY) ) return (-1); == -1) if( ( outfile = open(name2, O_WRONLY O_CREAT | O_TRUNC, PERM) ) == -1) return (-1); // // You need to read the contents of infile and copy to outfile (2 times!) copying! //// } close(infile); close (outfile); return 1; Fill out this part!! - main loop(s) for duplicate int main(int argc, char *argv) { } int main(int argc, char *argv) { if (argc!=3) { printf("Usage: dupFiles file1 file2 \n"); exit(-1); } } int retcode=-1; retcode = dupFile(argv[1], argv[2]);
Expert Answer:
Related Book For
Introduction to Management Science A Modeling and Cases Studies Approach with Spreadsheets
ISBN: 978-0078024061
5th edition
Authors: Frederick S. Hillier, Mark S. Hillier
Posted Date:
Students also viewed these accounting questions
-
Case study-1: A firm sells its products for $100 per unit, has variable costs of $50 per unit and fixed operating costs of $50,000 per year. Its current level of sales is 2,000 units. Show the...
-
Question: Old MathJax webview Old MathJax webview i need ans of these question but the source is alot Old MathJax webviewOld MathJax webview i need ans of these question but the source is alot these...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
If you place a charged object next to an uncharged object thatis a conductor, If you place a charged object next to an uncharged object thatis a conductor, A) The force depends on whether the charge...
-
It has just been reported that Happy Smile toothpaste reduces your cavities by 70 percent, while whitening your teeth and freshening your breath. Using supply and demand curves, demonstrate the...
-
Let A be m n with columns C1, C2, . . . , Cn. (a) If {C1, . . ., Cn} is independent, show null A = 0. (b) If null A = 0, show that {C1, . . .,Cn) is independent.
-
What are the needs theories of motivation?
-
Planet Publishing Limited (Planet) is a medium-sized, privately owned Canadian company that holds exclusive Canadian distribution rights for the publications of Typset Daily Corporation (TDC). Space...
-
Question 1 (1 point) Consider the following measures shown in the diagram with the circle centered at Point A. Determine the arc length of CB 40 A 6 cm B 4114 (i.e. Find the length of the arc...
-
According to the World Health Organization (WHO), in 2019, a new strain of the coronavirus disease was discovered. Also known as COVID-19, this strain of the virus had previously not been identified...
-
In the cross (or vector) product F = qx B we know that = 1 F= -50 + 10 +-40k 4.0 + 4.0 + 6.0k B = Bi+ By + Bk What then is B in unit-vector notation if Bx = By?
-
A load of 75-j250 is connected to one end (z = 0) of a lossless 502 line with a length of 0.32, use Smith chart to find the following: (1) at the load location (magnitude and phase) (2) I at the...
-
Write a MATLAB program to simulate the following experiments. (a) Draw a dice 100 times. That is, generate a sequence of 100 random numbers from the set {1,...,6}. Call this sequence X,..., X100....
-
Based on the Indian Bollywood movie The Tashkent Files Case Analysis Template Read the case you are assigned. Review the case analysis PowerPoint posted on Blackboard. Use the case analysis template...
-
How does the follower leadership lesson in this video align with you as a future healthcare leader? And why is it important to nurture the first few followers as equals, making everything clearly...
-
Write the dual from the following linear programming model: Max Z = 3 X 1 + 2 X 2 + 5 X 3 S . TO: X 1 + 2 X 2 + X 3 < = 4 3 0 3 X 1 + 2 X 3 < = 4 6 0 X 1 + 4 X 2 < = 4 2 0 X 1 , X 2 , X 3 > = 0
-
Explain the term global capital markets. This chapter primarily discusses global equity markets. What other types of financial instruments are traded in these markets? How important are global...
-
Time value is the anticipation of intrinsic value being stronger than it is now. However, intrinsic value can drop. Why then can time value not be negative?
-
In concrete terms, what does the difficulty in valuing an option boil down to?
-
Show how the purchase of an option and the sale of another option can protect you against the risk of a drop in the value of the underlying share, without costing you anything if you give up the...
Study smarter with the SolutionInn App