Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c programming language In this assignment, you are to implement and test functions char Wish read line(FILE in ) and int wish read config(char

In c programming language

image text in transcribedimage text in transcribedimage text in transcribed

In this assignment, you are to implement and test functions char Wish read line(FILE in ) and int wish read config(char fname). The necessary constants are defined in the file wish.h (provided). Function char wish_read_line(FILE in ) shall read up to WISH MAX INPUT characters from the previously opened file in. The newline character, if any, shall be removed from the line. The function shall allocate enough memory to store the input as a NULLterminated character string and return a pointer to the buffer. If any I/O or memory operation fails, the function shall print an error message with perror() and return NULL. If the input is longer than WISH MAX INPUT, the function shall discard it (to the next newline, including the newline itself), return NULL, and display the following error message to stderr: wish: line too long If the line is blank (empty or consists only of white spaces, as defined by isspace()), the function shall return NULL. You are encouraged to use the library function getline() to implement wish read line() but may choose to resort to fgets(). Function int wish_read_config(char fname, int ok if missing) shall read all lines from the file fname using the function wish read line. The function is responsible for opening and closing the file and reporting any errors associated with opening or closing the file using perror(). However, if the file does not exist and the parameter ok if missing is 1, the function shall do nothing (in particular, not report an error). The function shall return 0 in case of success and 1 in case of failure. Write function int main(int argc, char *argv[l] that shall read the commands from the previously created file wish.conf (provided) located in the SHOME directory 1. The program then shall display the prompt wISH DEFAULI PROMPT and read a command from stdin using Wish read line. The program shall then free all previously allocated memory. The program shall successfully terminate by returning EXIT SUCCESS. If any of the involved functions fails, the program shall return EXIT FAILURE. The main function shall be implemented in the file wish.c (provided). The other two functions shall be implemented in the file wish read.c (provided). The files must include wish h. 1 Function getenv() reads the value of a shell variable, such as \$Home. The project must have a Makefile (provided) with all the necessary dependencies. I will build your project (and you should, too) by running make without any parameters. If I run make again without modifying the submitted files, the project should not be rebuilt. When I type make clean, the files that can be rebuilt (e.g., wish, wish.o, and wish read.o) shall be deleted. Those files should not be placed under version control

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago