Question
Write a function which takes a filename as input. 1)If the file exist, it will display the content of the file. 2)Next use the case
Write a function which takes a filename as input. 1)If the file exist, it will display the content of the file. 2)Next use the case structure to display a command menu, and prompt the user for selection. Depending on the users selection, the user is allowed to write, append, edit the file, or exit the menu. 3)In case the users selection is invalid, prompt the user no valid selection is made. 4)If the file doesnt exist it will open the file in vi or vim. So you can write in the file and save it. 5)The program should complete all 3 Task examples below.
COMMAND MENU
Enter 1 write to file (Using cat) Enter 2 append to file (Using cat) Enter 3 edit file (Open vi) Enter 4 exit menu (show Bye and exit from program)
Task(1) Enter a filname. fruits
Displaying the file: banana apple orange
COMMAND MENU
Enter 1 to write to file Enter 2 to append to file Enter 3 to edit file Enter 4 to exit menu Enter an option: 4 BYE BYE
Task(2)
Enter a filename. newFile Creating a new file called newFile :
Task(3) Enter a filename. country
Displaying the file: USA Canada Brazil, Lets continue writing.
COMMAND MENU
Enter 1 to write to file Enter 2 to append to file Enter 3 to edit file Enter 4 to exit menu Enter an option: 6 You did not enter valid option.
Step 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