copyReverse.c code please do not change anything in the code besides the (four slashes ex.////)
/* copyReverse -- copyReverse namel to name2 */ #include #include #include #include
#include // !!! DO NOT CHNAGE BUFSIZE #define BUFSIZE 100 /* size of chunk to
be read */ #define PERM 0644 /* file permission for new file */ // sawpping two char
variables pointed by a and b // e.g., if you want to swap two variables, buf[i] and buf[j] //
you should call "swap(&buffer[i], &buffer[j])" by passing references (i.e., addresses) void
swap(char* a, char* b) { char t = *a; *a = *b; *b = t; } /* copyReverse namel to name2
*/ int copyReverse( const char *namel, const char *name2) { int infile, outfile; ssize_t
nread; char buffer[BUFSIZE]; if( ( infile = open(namel, O_RDONLY) ) == -1) return (-
1); if((outfile = open(name2,O_WRONLY|O_CREAT|O_TRUNC,PERM))==-1) { close
(infile); return (-2); } // find out the size of file (name1) by using lseek call ////int fSize =
lseek( ... ); // find out the number of blocks you need to read-reverse-write ////int numBlocks =
... // find out the size of partial block at the end ////int sizePartialBlock = ... // find the location
of RWP to be moved if sizePartialBlock > 0 int begBlockIdx = fSize - sizePartialBlock; // if
sizePartialBlock > 0, then you need to read it and reverse and write // you have to use lseek(),
read(), swap(), and write() calls to do this //*** it is recommended to use SEEK_SET flag in
lseek() call // //if(sizePartialBlock > 0) { //// //// //// //// //// } // Now, you need to reverse the
remaining blocks from the end //(except for the PartialBlcok) // int cnt = 0; // to keep track of
the number of blocks read/reversed while(cnt < numBlocks) { begBlockIdx = fSize -
sizePartialBlock - ((cnt+1) * BUFSIZE); // move the read-writer pointer to point to the
beginning of the // block to be read! You need to use lseek() //// //// // read one block bytes
(100 bytes) into buffer //from the (numBlocks-cnt)-th block from the beginning of name1 file
//// nread = read( ... ); //// // reverse bytes in buffer - you should use swap function declared
above //for swapping two char variables. Note nread contains the actual number //of bytes read.
//You may use additional extra array in this process - but there will //be some penalty if you do.
Try to do it within buffer[] //without using additional memory! //// //// // write reversed buffer
into name2 file - make sure to write only nread bytes //// //// cnt++; // increment the number of
blocks read/reversed/written } // end of while loop! close(infile); close (outfile); return(0);
// normal return } int main(int argc, char**argv) { if(argc!=3) { printf("Usage: copyReverse
file1 file2 \n"); exit(-1); } int retcode=0; retcode = copyReverse(argv[1], argv[2]); }the inputs
and outputs below as examples input1.txt It was many and many a year ago, In a kingdom by
the sea, That a maiden there lived whom you may know By the name of ANNABEL LEE;--
And this maiden she lived with no oth.
Play hard learn harder: The Serious Business of Play
copyReverse.c code please do not change anything in the code bes.pdf
1. copyReverse.c code please do not change anything in the code besides the (four slashes ex.////)
/* copyReverse -- copyReverse namel to name2 */ #include #include #include #include
#include // !!! DO NOT CHNAGE BUFSIZE #define BUFSIZE 100 /* size of chunk to
be read */ #define PERM 0644 /* file permission for new file */ // sawpping two char
variables pointed by a and b // e.g., if you want to swap two variables, buf[i] and buf[j] //
you should call "swap(&buffer[i], &buffer[j])" by passing references (i.e., addresses) void
swap(char* a, char* b) { char t = *a; *a = *b; *b = t; } /* copyReverse namel to name2
*/ int copyReverse( const char *namel, const char *name2) { int infile, outfile; ssize_t
nread; char buffer[BUFSIZE]; if( ( infile = open(namel, O_RDONLY) ) == -1) return (-
1); if((outfile = open(name2,O_WRONLY|O_CREAT|O_TRUNC,PERM))==-1) { close
(infile); return (-2); } // find out the size of file (name1) by using lseek call ////int fSize =
lseek( ... ); // find out the number of blocks you need to read-reverse-write ////int numBlocks =
... // find out the size of partial block at the end ////int sizePartialBlock = ... // find the location
of RWP to be moved if sizePartialBlock > 0 int begBlockIdx = fSize - sizePartialBlock; // if
sizePartialBlock > 0, then you need to read it and reverse and write // you have to use lseek(),
read(), swap(), and write() calls to do this //*** it is recommended to use SEEK_SET flag in
lseek() call // //if(sizePartialBlock > 0) { //// //// //// //// //// } // Now, you need to reverse the
remaining blocks from the end //(except for the PartialBlcok) // int cnt = 0; // to keep track of
the number of blocks read/reversed while(cnt < numBlocks) { begBlockIdx = fSize -
sizePartialBlock - ((cnt+1) * BUFSIZE); // move the read-writer pointer to point to the
beginning of the // block to be read! You need to use lseek() //// //// // read one block bytes
(100 bytes) into buffer //from the (numBlocks-cnt)-th block from the beginning of name1 file
//// nread = read( ... ); //// // reverse bytes in buffer - you should use swap function declared
above //for swapping two char variables. Note nread contains the actual number //of bytes read.
//You may use additional extra array in this process - but there will //be some penalty if you do.
Try to do it within buffer[] //without using additional memory! //// //// // write reversed buffer
into name2 file - make sure to write only nread bytes //// //// cnt++; // increment the number of
blocks read/reversed/written } // end of while loop! close(infile); close (outfile); return(0);
// normal return } int main(int argc, char**argv) { if(argc!=3) { printf("Usage: copyReverse
file1 file2 n"); exit(-1); } int retcode=0; retcode = copyReverse(argv[1], argv[2]); }the inputs
and outputs below as examples input1.txt It was many and many a year ago, In a kingdom by
the sea, That a maiden there lived whom you may know By the name of ANNABEL LEE;--
And this maiden she lived with no other thought Than to love and be loved by me. She was a
2. child and I was a child, In this kingdom by the sea, But we loved with a love that was more
than love-- I and my Annabel Lee-- With a love that the winged seraphs of heaven Coveted
her and me. And this was the reason that, long ago, In this kingdom by the sea, A wind blew
out of a cloud by night Chilling my Annabel Lee; So that her high-born kinsman came And
bore her away from me, To shut her up in a sepulchre In this kingdom by the sea. The angels,
not half so happy in Heaven, Went envying her and me:-- Yes! that was the reason (as all men
know, In this kingdom by the sea) That the wind came out of a cloud, chilling And killing my
Annabel Lee. But our love it was stronger by far than the love Of those who were older than
we-- Of many far wiser than we- And neither the angels in Heaven above, Nor the demons
down under the sea, Can ever dissever my soul from the soul Of the beautiful Annabel Lee:--
For the moon never beams without bringing me dreams Of the beautiful Annabel Lee; And the
stars never rise but I see the bright eyes Of the beautiful Annabel Lee; And so, all the night-
tide, I lie down by the side Of my darling, my darling, my life and my bride, In her sepulchre
there by the sea-- In her tomb by the side of the sea. input2.txt From childhood's hour I have
not been output1.txt .aes eht fo edis eht yb bmot reh nI --aes eht yb ereht erhclupes reh nI
,edirb ym dna efil ym ,gnilrad ym ,gnilrad ym fO edis eht yb nwod eil I ,edit-thgin eht lla ,os
dnA ;eeL lebannA lufituaeb eht fO seye thgirb eht ees I tub esir reven srats eht dnA ;eeL
lebannA lufituaeb eht fO smaerd em gnignirb tuohtiw smaeb reven noom eht roF --:eeL
lebannA lufituaeb eht fO luos eht morf luos ym revessid reve naC ,aes eht rednu nwod snomed
eht roN ,evoba nevaeH ni slegna eht rehtien dnA -ew naht resiw raf ynam fO --ew naht redlo
erew ohw esoht fO evol eht naht raf yb regnorts saw ti evol ruo tuB .eeL lebannA ym gnillik
dnA gnillihc ,duolc a fo tuo emac dniw eht tahT )aes eht yb modgnik siht nI ,wonk nem lla
sa( nosaer eht saw taht !seY --:em dna reh gniyvne tneW ,nevaeH ni yppah os flah ton ,slegna
ehT .aes eht yb modgnik siht nI erhclupes a ni pu reh tuhs oT ,em morf yawa reh erob dnA
emac namsnik nrob-hgih reh taht oS ;eeL lebannA ym gnillihC thgin yb duolc a fo tuo welb
dniw A ,aes eht yb modgnik siht nI ,oga gnol ,taht nosaer eht saw siht dnA .em dna reh
detevoC nevaeh fo shpares degniw eht taht evol a htiW --eeL lebannA ym dna I --evol naht
erom saw taht evol a htiw devol ew tuB ,aes eht yb modgnik siht nI ,dlihc a saw I dna dlihc a
saw ehS .em yb devol eb dna evol ot nahT thguoht rehto on htiw devil ehs nediam siht dnA --
;EEL LEBANNA fo eman eht yB wonk yam uoy mohw devil ereht nediam a tahT ,aes eht yb
modgnik a nI ,oga raey a ynam dna ynam saw tI output2.txt neeb ton evah I ruoh s'doohdlihc
morF
(3) You are allowed to use only the system calls covered in the class (e.g., read 0 , write ), open
0 , Iseek (, close()). You can't use library calls such as fread 0 , fopen 0 , fwrite 0 , etc. If you
don't follow this requirement, you will get significant penalty!! (4) Do not change other parts of
your program except for the parts beginning with four slashes - there are multiple parts.
3. Assignment Description: Given the template code, "copyReverse. c ", fill up the marked portion
so that your program is performing the following tasks: - Read from input file whose name is
pointed by argv[1]. - Write its reversed file contents into another file whose name is pointed by
argv/2]. - You need to use the given buffer size of 100. If you change this, there will be
significant point reduction. - Exception handling is important. If your program doesn't handle
exceptions of system call failure - e.g., open 0 , read , write(), lseek ( - then you will get some
penalty. - You should not change the given template code except for the part designated to be
filled up by you. The following is for your own programming and debugging purposes. The only
file you need to submit to codePost.io is "copyReverse.c" In Ubuntu, you can compile this
program as was discussed in the class: $> gec -0 copyReverse copyReverse.c
In Ubuntu, you can compile this program as was discussed in the class: $> gec -0 copyReverse
copyReverse.c After the compilation you need to run your program with two file names as
commandline arguments such as: S>./copyReverse filel.txt file2.txt Then your program is
supposed to create another file "file2.txt" from the existing file "file1.txt" after replacing each
occurrence of a lower-case character with an upper-case character. For example, if your input
file, file1.txt, contains: GAILY bedight, ABC A gallant knight, GAILY bedight, ABC A gallant
knight, GAILY bedight, ABC A gallant knight, GAILY bedight, ABC A gallant knight, GAILY
bedight, ABC A gallant knight, GAILY bedight, ABC A gallant knight, Then the outnut file file?
trt chould
"file1.txt" after replacing each occurrence of a lower-case character with an upper-case character.
For example, if your input file, file1.txt, contains: GAILY bedight, ABC A gallant knight,
GAILY bedight, ABC A gallant knight, GAILY bedight, ABC A gallant knight, GAILY bedight,
ABC A gallant knight, GAILY bedight, ABC A gallant knight, GAILY bedight, ABC A gallant
knight,