SlideShare a Scribd company logo
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
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.
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,

More Related Content

Similar to copyReverse.c code please do not change anything in the code bes.pdf

Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
Manav Prasad
 
Linux_Commands.pdf
Linux_Commands.pdfLinux_Commands.pdf
Linux_Commands.pdf
MarsMox
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
mugeshmsd5
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
egypt
 
Php extensions
Php extensionsPhp extensions
Php extensions
Elizabeth Smith
 
Php extensions
Php extensionsPhp extensions
Php extensions
Elizabeth Smith
 
Unix primer
Unix primerUnix primer
Unix primerdummy
 
Linuxppt
LinuxpptLinuxppt
LinuxpptReka
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.ppt
KiranMantri
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式
艾鍗科技
 
Question 1.Discuss at least three ways in which Henry David Thor.docx
Question 1.Discuss at least three ways in which Henry David Thor.docxQuestion 1.Discuss at least three ways in which Henry David Thor.docx
Question 1.Discuss at least three ways in which Henry David Thor.docx
IRESH3
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
byterock
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
Sasidhar Kothuru
 
Scripting 101
Scripting 101Scripting 101
Scripting 101
ohardebol
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Bhavsingh Maloth
 

Similar to copyReverse.c code please do not change anything in the code bes.pdf (20)

Computer Security
Computer SecurityComputer Security
Computer Security
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Linux_Commands.pdf
Linux_Commands.pdfLinux_Commands.pdf
Linux_Commands.pdf
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Unix primer
Unix primerUnix primer
Unix primer
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.ppt
 
Bash shell
Bash shellBash shell
Bash shell
 
Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式
 
Question 1.Discuss at least three ways in which Henry David Thor.docx
Question 1.Discuss at least three ways in which Henry David Thor.docxQuestion 1.Discuss at least three ways in which Henry David Thor.docx
Question 1.Discuss at least three ways in which Henry David Thor.docx
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Hawk presentation
Hawk presentationHawk presentation
Hawk presentation
 
Scripting 101
Scripting 101Scripting 101
Scripting 101
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 

More from murtuzadahadwala3

Create an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdfCreate an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdf
murtuzadahadwala3
 
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdfCreate a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
murtuzadahadwala3
 
Create an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdfCreate an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdf
murtuzadahadwala3
 
Create a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdfCreate a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdf
murtuzadahadwala3
 
Create a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdfCreate a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdf
murtuzadahadwala3
 
Create a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdfCreate a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdf
murtuzadahadwala3
 
Crane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdfCrane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdf
murtuzadahadwala3
 
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdfCount the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
murtuzadahadwala3
 
could you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdfcould you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdf
murtuzadahadwala3
 
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdfCOUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
murtuzadahadwala3
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdf
murtuzadahadwala3
 
Contrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdfContrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdf
murtuzadahadwala3
 
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdfContabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
murtuzadahadwala3
 
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdfContaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
murtuzadahadwala3
 
Constructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdfConstructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdf
murtuzadahadwala3
 
Consider the international strategy of a current entrepreneurial ve.pdf
Consider the international strategy of a current  entrepreneurial ve.pdfConsider the international strategy of a current  entrepreneurial ve.pdf
Consider the international strategy of a current entrepreneurial ve.pdf
murtuzadahadwala3
 
Consider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdfConsider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdf
murtuzadahadwala3
 
Consider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdfConsider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdf
murtuzadahadwala3
 
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdfComputer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
murtuzadahadwala3
 
Consider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdfConsider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdf
murtuzadahadwala3
 

More from murtuzadahadwala3 (20)

Create an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdfCreate an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdf
 
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdfCreate a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
 
Create an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdfCreate an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdf
 
Create a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdfCreate a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdf
 
Create a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdfCreate a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdf
 
Create a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdfCreate a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdf
 
Crane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdfCrane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdf
 
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdfCount the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
 
could you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdfcould you draw uml diagram for this code from PIL import Image, Im.pdf
could you draw uml diagram for this code from PIL import Image, Im.pdf
 
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdfCOUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdf
 
Contrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdfContrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdf
 
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdfContabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
 
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdfContaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
 
Constructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdfConstructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdf
 
Consider the international strategy of a current entrepreneurial ve.pdf
Consider the international strategy of a current  entrepreneurial ve.pdfConsider the international strategy of a current  entrepreneurial ve.pdf
Consider the international strategy of a current entrepreneurial ve.pdf
 
Consider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdfConsider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdf
 
Consider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdfConsider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdf
 
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdfComputer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
 
Consider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdfConsider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdf
 

Recently uploaded

Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 

Recently uploaded (20)

Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

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,