Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE DO IN C AND NOT IN C++. ALSO PLEASE USE BUFFERED I/O One night, three thieves stole a lot of money from a rich
PLEASE DO IN C AND NOT IN C++. ALSO PLEASE USE BUFFERED I/O
One night, three thieves stole a lot of money from a rich mans house. They put the money in a bag and went to the forest. They felt very hungry. So, one of them went to a nearby village to buy food. The other two remained in the forest to take care of the bag of money. The thief that went for food had an evil idea. He ate his food at a hotel. Then he bought food for his two mates in the forest. He mixed a strong poison with the food. He thought, Those two will eat this poisoned food and die. Then I will get all the money for myself. Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them. All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him. Then they ate the poisoned food and died. Thus, these evil people met with an evil end.
PLEASE DO IN C AND NOT IN C++. ALSO PLEASE USE BUFFERED I/O
Submit your .c (preferred) or .cpp solution file on Blackboard Objective: I/O Systems calls open, close, read, write, lseek and struct stat Using system calls you have learned so far, build your own command called fpart to display (or echo) a portion of any text file. Your program MUST detect if the input file is an ASCII text file or not. If the input file is NOT an ASCII file, then you must print an error. See step 1j. You must follow the following requirements. 1. Your command should be able to type-in scenarios a thru I (see below) and execute appropriately a. Sfpart filename.txt start_byte end_byte b. fpart filename.txt start_byte c. fpart filename.txt start_byte_is_larger_than_file size d. fpart filename.txt start_byte end_byte_pass_eof (Print up to the end of file) e. Sfpart filename.txt start_byte end_byte_smaller_than_start_byte (Error end must be greater than start f. fpart filename.txt (Error, too few arguments. Show error Message.) g. fpart filename.txt start_byte end_byte another_number (Error, too many arguments. Show error Message.) h. fpart (Error, No file name given. Show error message) i. fpart badfile.txt (Error, non-existing file name given. Show error message) j. fpart nonascill_file.exe 100 (Error, file is not an ascii file. Show error message) See detailed execution descriptions you must implement for each of the above steps 2. Example runs Assume your input text file is like this: (file name story.txt) One night, three thieves stole a lot of money from a rich man's house. They put the money in a bag and went to the forest. They felt very hungry. So, one of them went to a nearby village to buy food The other two remained in the forest to take care of the bag of money. The thief that went for food had an evil idea. He ate his food at a hotel. Then he bought food for his two mates in the forest. He mixed a strong poison with the food. He thought, "Those two will eat this poisoned food and die Then I will get all the money for myself." Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him Then they ate the poisoned food and died. Thus, these evil people met with an evil end Scenario 1 a: user enters valid parameters (a correct file name, correct start and end points). Prints result read from the input file from start point to the end point (inclusive) $./fpart story.txt 10 100 $./fpart story.txt 10 100 , three thieves stole a lot of money from a rich man's house. They put the money in a bag a Scenario 1 b: user enters valid parameters (a correct file name, correct start point but no end point) Prints result read from the input file from start point to the end of file $./fpart story.txt 500 Then I will get all the money for myself." Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them. All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him. Then they ate the poisoned food and died. Thus, these evil people met with an evil end Scenario 1 c: user enters a start point number larger than the file size. Then print an error as shown below $ ./fpart story.txt 1000000 Error start is too large, passed file size Scenario 1 d: user entered parameters where the end point requested is larger the than the file size? Then print from the start point requested to the size of the file $./fpart story.txt 10 10000 three thieves stole a lot of money from a rich man's house. They put the money in a bag and went to the forest. They felt very hungry. So, one of them went to a nearby village to buy food. The other two remained in the forest to take care of the bag of money. The thief that went for food had an evil idea. He ate his food at a hotel. Then he bought food for his two mates in the forest. He mixed a strong poison with the food. He thought. "Those two will eat this poisoned food and die. Then I a strong poison with the food. He thought, "Those two will eat this poisoned food and die. Then I will get all the money for myself." Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them. All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him. Then they ate the poisoned food and died. Thus, these evil people met with an evil end Following error conditions must be caught and display a message Scenario 1 e: What if the user entered parameters where the end point requested is smaller or equal to the start point? Then print an error $./fpart story.txt 30 5 Error: end must be greater than start Scenario 1f: What if the user entered parameters where there is no start point and end point? Then print an error as shown below. s ./fpart story.txt ErrorToO Less Parameters Usage fpart filename start [end] Scenario 1 g: What if the user entered parameters more than wanted by the command? Then print an error as shown below. $ ./fpart story.txt 30 5 10 Error: Too Many Parameters usage fpart filename start [end] Scenario 1 h: What if the user entered no file name? Then print an error as shown below. $ /fpart Error: Can't execute. Not enough arguments Scenario 1 i: What if the user entered non existing file name? Then print an error as shown below. $ /fpart unknown.txt Error: Failed to open file unknown.txt Scenario 1 j: What if the user entered non ASCII file name? Then print an error as shown below. $ ./fpart fpart.exe Error: File fpart.exe is not an ASCII file.Error: Failed to open file unknown.txt You must implement all the above steps for full credit. Use a header like this at the top of the file. /**@file yourfilename.c This file contains the kernel's *main) function. You should add your own comments to replace this one. * @author John Smith Submit your .c (preferred) or .cpp solution file on Blackboard Objective: I/O Systems calls open, close, read, write, lseek and struct stat Using system calls you have learned so far, build your own command called fpart to display (or echo) a portion of any text file. Your program MUST detect if the input file is an ASCII text file or not. If the input file is NOT an ASCII file, then you must print an error. See step 1j. You must follow the following requirements. 1. Your command should be able to type-in scenarios a thru I (see below) and execute appropriately a. Sfpart filename.txt start_byte end_byte b. fpart filename.txt start_byte c. fpart filename.txt start_byte_is_larger_than_file size d. fpart filename.txt start_byte end_byte_pass_eof (Print up to the end of file) e. Sfpart filename.txt start_byte end_byte_smaller_than_start_byte (Error end must be greater than start f. fpart filename.txt (Error, too few arguments. Show error Message.) g. fpart filename.txt start_byte end_byte another_number (Error, too many arguments. Show error Message.) h. fpart (Error, No file name given. Show error message) i. fpart badfile.txt (Error, non-existing file name given. Show error message) j. fpart nonascill_file.exe 100 (Error, file is not an ascii file. Show error message) See detailed execution descriptions you must implement for each of the above steps 2. Example runs Assume your input text file is like this: (file name story.txt) One night, three thieves stole a lot of money from a rich man's house. They put the money in a bag and went to the forest. They felt very hungry. So, one of them went to a nearby village to buy food The other two remained in the forest to take care of the bag of money. The thief that went for food had an evil idea. He ate his food at a hotel. Then he bought food for his two mates in the forest. He mixed a strong poison with the food. He thought, "Those two will eat this poisoned food and die Then I will get all the money for myself." Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him Then they ate the poisoned food and died. Thus, these evil people met with an evil end Scenario 1 a: user enters valid parameters (a correct file name, correct start and end points). Prints result read from the input file from start point to the end point (inclusive) $./fpart story.txt 10 100 $./fpart story.txt 10 100 , three thieves stole a lot of money from a rich man's house. They put the money in a bag a Scenario 1 b: user enters valid parameters (a correct file name, correct start point but no end point) Prints result read from the input file from start point to the end of file $./fpart story.txt 500 Then I will get all the money for myself." Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them. All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him. Then they ate the poisoned food and died. Thus, these evil people met with an evil end Scenario 1 c: user enters a start point number larger than the file size. Then print an error as shown below $ ./fpart story.txt 1000000 Error start is too large, passed file size Scenario 1 d: user entered parameters where the end point requested is larger the than the file size? Then print from the start point requested to the size of the file $./fpart story.txt 10 10000 three thieves stole a lot of money from a rich man's house. They put the money in a bag and went to the forest. They felt very hungry. So, one of them went to a nearby village to buy food. The other two remained in the forest to take care of the bag of money. The thief that went for food had an evil idea. He ate his food at a hotel. Then he bought food for his two mates in the forest. He mixed a strong poison with the food. He thought. "Those two will eat this poisoned food and die. Then I a strong poison with the food. He thought, "Those two will eat this poisoned food and die. Then I will get all the money for myself." Meanwhile, the two wicked men in the forest decided to kill their mate on return. They thought that they would divide the money between the two of them. All the three wicked men carried out their cruel plans. The thief who wanted all the money for himself came to the forest with the poisoned food. The two men in the forest hit him and killed him. Then they ate the poisoned food and died. Thus, these evil people met with an evil end Following error conditions must be caught and display a message Scenario 1 e: What if the user entered parameters where the end point requested is smaller or equal to the start point? Then print an error $./fpart story.txt 30 5 Error: end must be greater than start Scenario 1f: What if the user entered parameters where there is no start point and end point? Then print an error as shown below. s ./fpart story.txt ErrorToO Less Parameters Usage fpart filename start [end] Scenario 1 g: What if the user entered parameters more than wanted by the command? Then print an error as shown below. $ ./fpart story.txt 30 5 10 Error: Too Many Parameters usage fpart filename start [end] Scenario 1 h: What if the user entered no file name? Then print an error as shown below. $ /fpart Error: Can't execute. Not enough arguments Scenario 1 i: What if the user entered non existing file name? Then print an error as shown below. $ /fpart unknown.txt Error: Failed to open file unknown.txt Scenario 1 j: What if the user entered non ASCII file name? Then print an error as shown below. $ ./fpart fpart.exe Error: File fpart.exe is not an ASCII file.Error: Failed to open file unknown.txt You must implement all the above steps for full credit. Use a header like this at the top of the file. /**@file yourfilename.c This file contains the kernel's *main) function. You should add your own comments to replace this one. * @author John SmithStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started