Question: C program assignment! C only. no other language. assgn2_input.txt is given file. Thanks! Given a file, assgn2_input.txt, uploaded into the assignment folder, create a program
C program assignment! C only. no other language. assgn2_input.txt is given file. Thanks!
Given a file, assgn2_input.txt, uploaded into the assignment folder, create a program with the following functionality.
- Create the following function:
- int convert_copyfile(const char* name1, const char* name2)
- this function should return the number of conversions made (the to THE).
- If the target file (second argument) doesnt exist, then your program should create an empty file for writing.
- If the target file (second argument) exists, then your program should exit with error message without doing anything.
- Use the combination of option flags in open() system call we covered in the class.
- Use BUFSIZE=100 to iteratively read bytes from the input file and write converted bytes into the output file. (Use while loop as in the example program.)
- While reading bytes, you should
- Keep track of the number of occurrences of the word in the file. (Case sensitive)
- While writing bytes to the output file, you should
- Replace any occurrence of the word with THE word.
- Then, write back the modified contents to the output file.
- Create main() function which makes the following call:
- Convert_copyfile(assign2_input.txt, assgn2_output.txt);
- Print out the total number of conversions made (from the to THE);
- Print out the contents of assgn2_output.txt file at the end of your program.
assgn2_input.txt has the following text in it.
Its a peculiar appartheus, said the Officer the the Traveller, gaztheg with a certathe admirtheithe the the device, with which he was, of course, thoroughly familiar. It appeared ththe the Traveller had resptheded the the thevittheithe of the Commandant thely out of politeness, when he had been asked the thetend the executithe of a soldier cthedemned for disobeytheg and thesulttheg his superior. Of course, theterest the the executithe was not very high even the the penal colthey itself. At least, here the the small, deep, sandy valley, closed the the all sides by barren slopes, apart from the Officer and the Traveller there were present thely the Cthedemned, a vacant-looktheg man with a broad mouth and dilapidtheed hair and face, and the Soldier, who held the heavy chathe the which were cthenected the small chathes which bound the Cthedemned Man by his feet and wrist bthees, as well as by his neck, and which were also ltheked the each other by cthenecttheg chathes. The Cthedemned Man, thecidentally, had an expressithe of such dog-like resigntheithe ththe it looked as if thee could set him free the roam around the slopes and would thely have the whistle the the start of the executithe for him the return. The Traveller had little theterest the the appartheus and walked back and forth behthed the Cthedemned Man, almost visibly thedifferent, while the Officer theok care of the ftheal prepartheithes. Sometimes he crawled under the appartheus, which was built deep thethe the earth, and sometimes he climbed up a ladder the thespect the upper parts. These were really jobs which could have been left the a mechanic, but the Officer carried them out with grethe enthusiasm, maybe because he was particularly fthed of this appartheus or maybe because there was some other reasthe why thee could not trust the work the anythee else. Its all ready now! he ftheally cried and climbed back down the ladder. He was unusually tired, brethehtheg with his mouth wide open, and he had pushed two fthee ladys handkerchiefs under the collar of his uniform. These uniforms are really theo heavy for the tropics, the Traveller said, thestead of asktheg some questithes about the appartheus, as the Officer had expected. Ththes true, said the Officer. He washed the oil and grease from his dirty hands the a bucket of wtheer standtheg ready, but they mean home, and we dthet want the lose our homeland. Now, have a look the this appartheus, he added immeditheely, drytheg his hands with a thewel and pothettheg the the device. Up the this pothet I had the do some work by hand, but from now the the appartheus should work entirely the its own. The Traveller nodded and followed the Officer. The ltheter tried the protect himself agathest all eventualities by saytheg, Of course, breakdowns do happen. I really hope nthee will occur theday, but we must be prepared for it. The appartheus is supposed the keep gotheg for twelve hours without theterruptithe. But if any breakdowns do occur, theyll thely be very mtheor, and well deal with them right away. Dthet you want the sit down? he asked ftheally, as he pulled out a chair from a pile of cane chairs and offered it the the Traveller. The ltheter could not refuse. He sthe the the edge of the pit, thethe which he cast a fleettheg glance. It was not very deep. On thee side of the hole the piled earth was heaped up thethe a wall; the the other side stheod the appartheus. I dthet know, the Officer said, whether the Commandant has already explatheed the appartheus the you. The Traveller made an vague gesture with his hand. Ththe was good enough for the Officer, for now he could explathe the appartheus himself. This appartheus, he said, grasptheg a cthenecttheg rod and leantheg agathest it, is our previous Commandants theventithe. I also worked with him the the very first tests and theok part the all the work right up the its completithe. However, the credit for the theventithe belthegs the him althee. Have you heard of our previous Commandant? No? Well, Im not claimtheg theo much when I say ththe the organiztheithe of the entire penal colthey is his work. We, his friends, already knew the the time of his detheh ththe the admtheistrtheithe of the colthey was so self-cthetatheed ththe even if his successor had a thousand new plans the mthed, he would not be able the alter anyththeg of the old plan, the least not for several years. And our predictithe has held. The New Commandant has had the recognize ththe. Its a shame ththe you didnt know the previous Commandant!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
